I have the following class:
[code=php]
class zipcode_class {
var $last_error = “”;
var $last_time = 0;
var $units = _UNIT_MILES;
var $decimals = 2;
function get_zip_point($zip) {
$sql = “SELECT lat, lon from zip_code WHERE zip_code=’$zip'”;
$r = mysql_query($sql);
if (!$r) {
$this->last_error = mysql_error();
return false;
}
$row = mysql_fetch_array($r);
if(mysql_num_rows($r) == 0) {
$mess = “Zip Code Not Found”;
return $mess;
} else {
mysql_free_result($r);
return $row;
}
}
function get_zips_in_range($zip, $range, $sort, $include_base) {
$this->chronometer();
$details = $this->get_zip_point($zip);
if ($details == false) return false;
$lat_range = $range/69.172;
$lon_range = abs($range/(cos($details[0]) * 69.172));
$min_lat = number_format($details[0] – $lat_range, “4”, “.”, “”);
$max_lat = number_format($details[0] + $lat_range, “4”, “.”, “”);
$min_lon = number_format($details[1] – $lon_range, “4”, “.”, “”);
$max_lon = number_format($details[1] + $lon_range, “4”, “.”, “”);
$return = array(); // declared here for scope
$r = mysql_query(“SELECT zip_code, lat, lon FROM zip_code WHERE lat BETWEEN ‘$min_lat’ AND ‘$max_lat’ AND lon BETWEEN ‘$min_lon’ AND ‘$max_lon'”) or die(mysql_error());
while ($row = mysql_fetch_row($r)) {
$dist = $this->calculate_mileage($details[0],$row[1],$details[1],$row[2]);
if ($this->units == _UNIT_KILOMETERS) {
$dist = $dist * _M2KM_FACTOR;
}
if ($dist <= $range) {
$return[str_pad($row[0], 5, “0”, STR_PAD_LEFT)] = round($dist, $this->decimals);
}
}
mysql_free_result($r);
switch($sort) {
case _ZIPS_SORT_BY_DISTANCE_ASC:
asort($return);
break;
case _ZIPS_SORT_BY_DISTANCE_DESC:
arsort($return);
break;
case _ZIPS_SORT_BY_ZIP_ASC:
ksort($return);
break;
case _ZIPS_SORT_BY_ZIP_DESC:
krsort($return);
break;
}
$this->last_time = $this->chronometer();
if (empty($return)) return false;
return $return;
}
}
And when I instantiate the class and call the function doing the following:
[code=php]
$zips = new zipcode_class();
$zips->get_zips_in_range($zip, $miles, _ZIPS_SORT_BY_DISTANCE_ASC, true);
I cycle through the $zips array using a foreach loop and all I get as output are the names of the variables, not the values: last_error, last_time, units m, decimals 2
Am I instantiating the class wrong or handling the array wrong???