= " . $distance2 . ") ";
endif;
// $whereClauseDistance = " AND " . $whereClauseDistance;
$sqlStmt = "SELECT crd.cr_zipcode, crd.cr_city, crd.cr_district, lat, lng,"
. " (ACOS((SIN(" . deg2rad($lat) . ")*SIN(RADIANS(crd.lat))) + (COS(" . deg2rad($lat) . ")*COS(RADIANS(crd.lat))*COS(RADIANS(crd.lng) - " . deg2rad($long) . "))) * " . $geoEarthRadius . ") AS distance"
. " FROM phoenix_special.cityradius AS crd"
. " WHERE " . $whereClauseDistance
. " ORDER BY crd.cr_city, crd.cr_zipcode, crd.cr_district";
// echo "
" . $sqlStmt . "
"; die();
$result = $db->query($sqlStmt);
if (DB::isError($result)) die ("$PHP_SELF:
$sqlStmt
" . $result->getMessage());
while ($row = $result->fetch_assoc()):
$retArray[] = array($row["cr_city"],$row["cr_zipcode"],$row["cr_district"],$row["lat"],$row["lng"],$row["distance"]);
endwhile;
$result->free();
endif;
return $retArray;
}
// Inserts a row into table "serviceradius"
function insertServiceRadius ($dataArray = array(), $hq_id = "0", $cs_id = "0", $radiusAreaNo = "", $dataIncArray = array()) {
global $db, $PHP_SELF;
$srvr_id_new = "0";
$dataArrayLen = count($dataArray);
$dataIncArrayLen = count($dataIncArray);
if ($dataArrayLen > 0) :
// ARRAY: (cr_city, cr_zipcode, cr_district, lat, lng, distance)
$city = $dataArray[0];
$zipcode = $dataArray[1];
$district = $dataArray[2];
// [1.] Check for empty district regarding the following row having the same city and the same zipcode.
// If the following data row has a district (!= ""), then do NOT use the current row WITHOUT a district name!
// [2.] Check for potential doublets.
$execInsert = true;
if ($dataIncArrayLen > 0) :
$cityInc = $dataIncArray[0];
$zipcodeInc = $dataIncArray[1];
$districtInc = $dataIncArray[2];
// [1.]
if ($district == "") :
if ($city == $cityInc && $zipcode == $zipcodeInc && $districtInc != "") :
$execInsert = false;
endif;
endif;
// [2.]
if ($execInsert) :
if ($city == $cityInc && $zipcode == $zipcodeInc && $district == $districtInc) :
$execInsert = false;
endif;
endif;
endif;
if ($execInsert) :
if ($radiusAreaNo != "" && is_numeric($radiusAreaNo)) :
if ($district == "") : $district = $city; endif;
insertStmt("serviceradius", array("hq_id", $hq_id, "cs_id", $cs_id, "srvr_zipcode", $zipcode, "srvr_city_district", $district, "srvr_radiusarea_no", $radiusAreaNo));
$srvr_id_new = getLastInsertId();
endif;
endif;
endif;
return $srvr_id_new;
}
?>