...

View Full Version : Custom php function inside MySQL query.



muneeba9071
09-13-2011, 04:22 AM
Hi,

I have a MySQL DB table which has location names stored in. I have a PHP function which returns mile distance when two locations are given to it as arguments, for example:



get_distance(start_location,end_location);


The above will return total number of miles. Now, I have a MySQL query where I want to run a real time mileage check and sort the query by the returned mile distance (closest location first), for example something like below would be great!



mysql_query("SELECT * FROM locations ORDER BY get_distance(location1,location2) ASC";


I would really very appreciate if someone could help!

Many Thanks
[/CODE]

BluePanther
09-13-2011, 04:44 AM
This isn't really a PHP question, more a mysql question. The php works fine, you're just wanting to use mysql query to show you closest locations first.

But I can maybe suggest a solution depending on more info from you. You're wanting a location that's close to the result of get_distance()? You're wanting locations close to the distance between location 1 and location 2? Seems odd to me, as the distance between 2 objects is completely unrelated to an actual location of something. Please elaborate a bit.

Inigoesdr
09-13-2011, 09:17 PM
You would have to show the maths you are doing in get_location() for us to be able to help you out. If it's something simple like location2 - location1 that's easy.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum