Jump to content

Showing number of items with distance


kaneos

Recommended Posts

I have a page that gets the closest stores to a latitude and longitude. I want to have a MySQL table like this:

 

location_id:::::items

 

showing how many items are at each store and then show 'spit' them in the following format with the lowest number of items first:

 

location_id, distance to location_id, items.

 

here is the code I am using to show location_id by distance

 

 

<?php

include "connectionfile.php";

$lat = $_GET["lat"];
$lng = $_GET["lng"];


$sql = mysql_query("SELECT id, ( 6371 * acos( cos( radians($lat) ) * cos( radians( lat ) )
  * cos( radians( lng ) - radians($lng) ) + sin( radians($lat) ) 
  * sin( radians( lat ) ) ) ) AS distance
FROM locations
HAVING distance < 250
ORDER BY distance LIMIT 0 , 60;
");

WHILE($lstlocations = mysql_fetch_array($sql)) {
$location_id[$count]=$lstlocations['id'];
$distance=$lstlocations['distance'];

echo "id = " . $location_id[$count] . "  Distance = " . $distance. "<br>";
$count = $count + 1;
}

?>

 

What would be the best way to achieve this?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.