Custom MySQL Order By depending on a PHP function value -
Custom MySQL Order By depending on a PHP function value -
i have database this
http://i.stack.imgur.com/mhewr.jpg
i have php function compute distance { get_distance ($person_location) } of address user (web user).
i need have query utilize function , homecoming info database order distance user [using { get_distance ($person_location) } function of php].
can help me please?
you can't sort sql results on serverside result of php function.*
there 2 approaches general problem:
1. move calculation sqlyour distance computation relies on geo-coordinates (latitude , longitude). save info every address in database , distance computation in sql well.
find more on how in mysql here: fastest way find distance between 2 lat/long points
your todo list this. next things once:
get addresses db calculate geo coordinates each address php api update database , set geo coordinates in columnsdo next things on:
every time add together row table, calculate geo coordinates beforehand api , add together them well every time alter address in database, calculate new geo coordinates php api , update them well every time need calculate distance current user other addresses,select
query computes distance , sorting 2. in php query database addresses, set them php array, compute distance current user function , sort array.
i suggest not that, however, , implement on server-side (approach 1).
* well in theory could, calulcating distance every address offline, updating temporary table result, , querying table 1 time again using temporary table sort results. however, worse doing in php, shouldn't consider this!
php mysql sql web laravel-4
Comments
Post a Comment