Can't Seem to get the array to fill up with zipcodes
function inradius($zipOne,$radius,$units,$sort)
{
global $db;
#-- Trim strip leading and trailing spaces
$zipOne=trim($zipOne);
if ($units=="km")
$km=1.61."*";
if ( isZipInSystem($zipOne))
$myZip = db_arr( "SELECT * FROM ZIPCodes WHERE ZIPCode = '$zipOne' ");
else return "First Zip Code not found";
if($myZip) {
$lat=$myZip['Latitude'];
$lon=$myZip['Longitude'];
//$query="SELECT ZIPCode, ($km(POW((69.172*(Longitude-\"$lon\")*cos($lat/57.2958)),\"2\")+POW((69.1*(Latitude-\"$lat\")),\"2\"))) AS distance FROM ZIPCodes WHERE ($km(POW((69.172*(Longitude-\"$lon\")*cos($lat/57.2958)),\"2\")+POW((69.1*(Latitude-\"$lat\")),\"2\")))<= ($radius*$radius) ORDER BY distance $sort";
$query=db_res("SELECT ZIPCode, ($km(POW((69.172*(Longitude-\"$lon\")*cos($lat/57.2958)),\"2\")+POW((69.1*(Latitude-\"$lat\")),\"2\"))) AS distance FROM ZIPCodes WHERE ($km(POW((69.172*(Longitude-\"$lon\")*cos($lat/57.2958)),\"2\")+POW((69.1*(Latitude-\"$lat\")),\"2\")))<= ($radius*$radius) ORDER BY distance $sort");
if($query) {
/* $i=0;
while(list($key, $val)= each($query) ) {
$zipArray[$key]=$query['ZIPCode'];
$i++;
} */
$zipArray= fill_array( $query );
}
}else{
return "Zip Code not found";
}
return $zipArray;
} // end function
The above is the fuction doing the zipcodes and creating the array...
The next segment is the db_res function
function db_res( $query, $error_checking = 1 )
{
global $BUG_REPORT_EMAIL;
global $MySQL;
$res = mysql_query( $query, $MySQL->link );
if ( $error_checking && !$res )
{
echo PrintErr( _t("_DB_ACCESS_ERROR"));
$msg = "Error in $_SERVER[PHP_SELF]: " . mysql_error() . "\nQuery: '$query'";
db_report_error( $msg);
}
return $res;
}
This function creates the array
function fill_array( $res )
{
global $MySQL;
if (!$res)
return false;
$i = 0;
while( $r = mysql_fetch_array( $res ) )
$arr[$i++] = $r;
return $arr;
}
Finally this snip displays the array
while (list($key, $val) = each($zipArray)) {
$distance = $zipLoc->distance($myZip,$val,$units);
$z_arr = db_arr("SELECT Latitude,Longitude FROM ZIPCodes WHERE ZIPCode = '$val'");
echo "$key => $val = $distance from $myZip at $z_arr[Latitude] and $z_arr[Longitude] <br>";
}
The output has the correct count of elements but the value is always Array...lol
I don't get it can some help or slap me around tell me what I'm doing wrong here?
0 => Array = First Zip Code not found from 94551 at and
1 => Array = First Zip Code not found from 94551 at and
2 => Array = First Zip Code not found from 94551 at and
3 => Array = First Zip Code not found from 94551 at and
4 => Array = First Zip Code not found from 94551 at and
5 => Array = First Zip Code not found from 94551 at and
6 => Array = First Zip Code not found from 94551 at and
7 => Array = First Zip Code not found from 94551 at and
8 => Array = First Zip Code not found from 94551 at and
9 => Array = First Zip Code not found from 94551 at and