0

I have a table which searches the theaters from database based on zip code, currently i have used this query to sort results, but i want the exact matched location first and then nearby location in while loop Is there any way, i have searched but all are showing that we need latitude and longitude to perform this search , but for now i haven't stored such info in database. Please advice.

   if($_GET['zip'])
  {
  $zip_get= trim($_GET['zip']);
    $zip_three=substr($zip_get, 0, 3);

  $theatre_query= mysql_query("select * from (Select *,(CASE WHEN zip = '$zip_get' THEN 2 ELSE 0 END + CASE WHEN zip < $zip_get  THEN 1  ELSE 0 END )  as nummatches  from theatre )  where nummatches>0 and campaign='$camp' and zip LIKE '".$zip_three."%' order by nummatches desc, zip desc");
  }
Raman
  • 624
  • 5
  • 13
  • 2
    If you're writing new code, **_please_ don't use the `mysql_*` functions**. They are old and broken, were deprecated in PHP 5.5 (which is so old it no longer even receives security updates), and completely removed in PHP 7. Use [`PDO`](https://secure.php.net/manual/en/book.pdo.php) or [`mysqli_*`](https://secure.php.net/manual/en/book.mysqli.php) with _prepared statements_ and _parameter binding_ instead. See http://stackoverflow.com/q/12859942/354577 for details. – ChrisGPT was on strike Dec 22 '16 at 03:54
  • ok thanks for the suggestion @Chris i will replace. – Raman Dec 22 '16 at 03:57
  • `$zip_three` is three digits from a zip code? Zip codes are geographically relevant? I'd use the haversine formula and geocode the zips. – chris85 Dec 22 '16 at 04:17
  • $zip_three was just used to sort . now i need different sort according to Distance. – Raman Dec 22 '16 at 06:30

0 Answers0