Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL ORDER BY nearest zone
    text
    copied!<p>Basically I have to get the algorithm to show restaurants in the selected zone and in other zones which actually makes sense.. </p> <p>E.g: if my area is in North of some city, I would like to show up restaurants in north, then move to central and then to east and then to west and finally to the extreme opposite i.e., south</p> <p>In case of east, then central, north, south, finally extreme opposite i.e., west</p> <p>I have in my db the following </p> <p>zones table with ids, 1 - North, 2 - East, 3 - West, 4 - South, 5 - Central.</p> <p>And localities table with locality/area of each city and structure goes as</p> <p>locality_id | locality_name | zone_id(FK) </p> <p>I have my model (php/codeigniter) </p> <pre><code>$this-&gt;db-&gt;select('menu_item.restaurant_id, menu_item.price, localities.locality_name, restaurant_information.restaurant_name, restaurant_information.restaurant_address, restaurant_information.is_halal, restaurant_information.cuisine, restaurant_information.city, restaurant_information.pincode'); $this-&gt;db-&gt;from('menu_item'); $this-&gt;db-&gt;where('menu_item.dish_id', $dish_id); $this-&gt;db-&gt;where('menu_item.is_active', 1); $this-&gt;db-&gt;where('restaurant_information.is_active', 1); $this-&gt;db-&gt;join('restaurant_information', 'menu_item.restaurant_id = restaurant_information.restaurant_id'); $this-&gt;db-&gt;join('localities', 'restaurant_information.locality_id = localities.locality_id'); </code></pre> <p>Its okay if I have too many joins or whatever.. but definitely not with lat/long or google geo..</p> <p>Please help me out.. I tried order_by_field.. Its okay and it works but I am not able to give it dynamically.. </p> <p>Is there any solution or am I headed in the wrong direction..? Correct me if I got the structure wrong..!</p> <p>And I am also ready if the order by part could be done on the result object where I can fetch the result and sort it based on the location.. but I prefer MySQL to do the job. Thanks in advance</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload