The following script will do what you want:
<?PHP
# Calculate distances in miles and kilometres
# 22.11.2005
# Author - Brit
# PHPBuilder thread ID - 10312768
/* 1. Define decimal place required for calculation results */
DEFINE("DECIMAL","1");
/* 2. How many kilometers in a mile? */
DEFINE("KM_CONVERT","1.609");
/* 3. How many miles in a kilometer? */
DEFINE("ML_CONVERT","0.62");
/* 4. Output conversion to screen? */
DEFINE("OUTPUT_RESULT",true);
/*************************************************************************************/
/* The rest of the script which you shouldn't need to change, happens below this break
/*************************************************************************************/
/*************************/
/* Convert supplied m->km, and vice versa.
/*************************/
$ml_value = trim($_GET["miles"]);
$km_value = trim($_GET["kilometers"]);
if($ml_value > 0)
{
/* Work out km */
$km_value = round(($ml_value*KM_CONVERT),DECIMAL);
}
else
{
/* Work out miles */
$ml_value = round(($km_value/ML_CONVERT),DECIMAL);
}
/* If output enabled, show it. */
if(OUTPUT_RESULT)
{
echo sprintf("<pre>Miles: %s<br>Kilometers: %s</pre>\n",$ml_value,$km_value);
}
?>
You'll need to modify it somewhat, but essentially, pass the script either a miles or kilometers distance and it'll return the other one, and then put those into your SQL query.
Regards,
Brit.