Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2008
    Posts
    120
    Thanks
    15
    Thanked 2 Times in 2 Posts

    Question Custom php function inside MySQL query.

    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:

    Code:
    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!

    Code:
    mysql_query("SELECT * FROM locations ORDER BY get_distance(location1,location2) ASC";
    I would really very appreciate if someone could help!

    Many Thanks
    [/CODE]

  • #2
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    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.

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •