Hey Guys.
I'm building a store locator from various scripts and i have ran in to problems.
I would like the out put to only list the nearest 5 stores.
currently i can only make it pull the nearest store within a certain distance (this is okay but would perfer if the results where in distance order).
Can any one help: $pcodeA will be generated by the user
<?php
include('script_var.php');
MYSQL_CONNECT("$host","$user","$pass");
mysql_select_db("$db");
///// POST CODES FOR THE STORES
$query = "SELECT * FROM postcodes_store";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
// if records present
if (mysql_num_rows($result) > 0) {
while($row = mysql_fetch_object($result)) {
$pcodeBB[] = $row->Pcode;
}
}
foreach ($pcodeBB as $value)
{
$pcodeB = "$value";
$pcodeA = HR2;
// PCODE A
$result2=mysql_query("SELECT * FROM postcodes WHERE Pcode='$pcodeA' LIMIT 1");
$row=mysql_fetch_array($result2);
$gridn[0]=$row[Grid_N];
$gride[0]=$row[Grid_E];
// PCODE B
$result3=mysql_query("SELECT * FROM postcodes WHERE Pcode='$pcodeB' LIMIT 1");
$row=mysql_fetch_array($result3);
$gridn[1]=$row[Grid_N];
$gride[1]=$row[Grid_E];
// TAKE GRID REFS FROM EACH OTHER.
$distance_n=$gridn[0]-$gridn[1];
$distance_e=$gride[0]-$gride[1];
// CALCULATE THE DISTANCE BETWEEN THE TWO POINTS
$hypot=sqrt(($distance_n$distance_n)+($distance_e$distance_e));
$text = round($hypot/1000,2);
if($text < 100)
{echo "$text<br>";}
}
?>