Jump to content

Help with search application


jumpenjuhosaphat

Recommended Posts

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.
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.