jumpenjuhosaphat Posted January 26, 2007 Share Posted January 26, 2007 I am trying to create a search application with multiple search fields. Everything works fine, except that one of the search queries depends on information from another table. Basically, it is a search app for an ad placement service. There is a function that I created that will tell the searcher how far an item is from their location based on their postalcode. That information is done in a function called distance_between(pointa, pointb), it requires information from a data base with coordinates, and does the necessary calculations based on the coords. It works as expected. Now when I create a query for mysql, each search item will create a new part of a query string, but the problem that I am having is that this search string could get to as big as 2800 different items if someone searches for items that are no more than 1000 miles from them. The sub query for the distance would then be like:[code]postarea=AB10 || postarea=AB11 || postarea=AB12 || postarea=AB13.......|| postarea=Z08[/code]The way that I have it now, I leave the distance out of the query, and search with the rest of the criteria. Then after the search is performed, I test each record with the distance_between function, if the distance is greater than the distance specified by the user, it simply skips this record, it doesn't display it. The problem with this, is that at the end of the query is [code]LIMIT $a, 10[/code]where $a specifies the page being viewed. It gives the results in pages of 10 records. If the page contains 10 records that are outside of the distance specified then no records will be displayed on that page, and that would just look strange and unprofessional.So is there a way that I can create a query, then test each record, and display exactly 10 results based on whether the record passed the test or not?I hope I've explained all of this good enough, it's kind of a tough one to explain. Quote Link to comment https://forums.phpfreaks.com/topic/35772-help-with-search-application/ Share on other sites More sharing options...
jumpenjuhosaphat Posted January 26, 2007 Author Share Posted January 26, 2007 If it were possible to do a conditional statement using a function within a query I think that would work, but I don't know how to go about that.So the query would be:[code]SELECT * FROM ads WHERE ..... && distance_between(adpostarea, userpostarea)<maximum_distance[/code]adpostarea in the distance_between function would be data from the table that is being queried.Is there a way of doing that? Quote Link to comment https://forums.phpfreaks.com/topic/35772-help-with-search-application/#findComment-169523 Share on other sites More sharing options...
fenway Posted January 26, 2007 Share Posted January 26, 2007 I don't think I understand what you mean. Quote Link to comment https://forums.phpfreaks.com/topic/35772-help-with-search-application/#findComment-169603 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.