I need some help with limiting a query if a user wants results within a certain radius of his zipcode. I already have the distance calculated with a function and can echo the distances on the search results. However, I don't know how to limit the results within a radius. I placed a "radius" field on the search page with a drop down for 5, 10, 50, 100,etc. with the value corresponding, so, I have $radius. How do I limit the results? I tried:
$squery.=(radius!="")?" and $dist<='$radius' ":"";
Below is a snippet of the code I have that doesn't work. Any help would be greatly appreciated!
// Code Snippet
$squery.=($waf6=="on")?" and uwaf6='on' ":"";
$squery.=($waf7=="on")?" and uwaf7='on' ":"";
// The problem begins here
// calculate_dist is a function included and works fine
if($radius!=""){
$query=" select * from users where utype>0";
$result=$db->query($query);
$count=$db->numrows($result);
for($i=0;$i<$count;$i++) {
$usera=new User;
$usera->fillvars(mysql_fetch_array ($result,MYSQL_ASSOC));
$dist=calculate_dist($user->uzip,$usera->uzip, $db);
echo $dist;
}
}
$squery.=($radius!="")?" and $dist<='$radius' ":" ";
// The rest of the search items below work fine, also
$squery.=($wam1=="on")?" and uwam1='on' ":"";
$squery.=($wam2=="on")?" and uwam2='on' ":"";
$squery.=($wam3=="on")?" and uwam3='on' ":"";
$squery.=($wam4=="on")?" and uwam4='on' ":"";
// End Code Snippet
The full page "results.php" is attached
Thanks for any help or holler if you need more info!
KP