Jump to content

Calling a function in a WHERE clause with data from the record in the parms!


CavySpirit

Recommended Posts

I was sure I had seen this being done somewhere else, but I sure as heck can't get it to work!

I have a mySQL query. Here's the important part:

SELECT other_fields,lat,lon FROM myfile WHERE distance(lat,lon,$centerlat,$centerlon,\"M\")<$radius

I have tried putting { } around the expression, tried making M a variable, etc. The big problem is lat and lon are NOT being passed in the expression and even if I just plug numbers in to test it, I'm getting column or syntax errors.

I am calling a function "distance" which returns the miles of the distance between two locations, the lat and longitude from the record and the one from the cookie. I am trying to only select the records that fall within the desired radius--say 50 miles. The function works. The center fields and radius are being input properly.

Please help???
Thanks,
Teresa
Link to comment
Share on other sites

If you have MySQL v5 you can define your own functions in which case it will work.

Otherwise you have to pull the lat and long and loop through the results, using that function on each record returned. to test if it's within the radius. Or read them all into an array and use an array filtering function to get the ones you want.
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.