
October 13th, 2008, 12:54 PM
|
|
Registered User
|
|
Join Date: Aug 2008
Posts: 16
Time spent in forums: 7 h 50 m 22 sec
Reputation Power: 0
|
|
|
Strange Occurence with zip code locator
Hi everyone, I have a strange thing happening with a zip code locator. I have two sets of zip codes that I have verified are in my data tables correctly. There are stores in the data base with these zipcodes. When entered into the page the zip code show a different store, it is not finding the actual store inside that zip code. I can't for the life of me figure out why this is happening.
Something to note is if I change the store zipcodes to a different zip code not in the two ranges that aren't working, the locator works perfect and finds the stores right away.
Thanks for your help
PHP Code:
<?php
require_once( 'classes/ZipCodesRange.class.php' );
// Get Values
$zip = $_POST['zip'];
$distance = 25;
$limit = 3;
$ret = '';
$count = 1;
$retArray = array();
if((is_numeric($zip)) && (strlen($zip) == 5)) {
//initialization, pass in DB connection, from zip code, distance in miles.
$dbInfo = mysql_connect('localhost', 'root', '******');
mysql_select_db('chd');
$rzip = new ZipCodesRange($dbInfo,$zip,$distance);
//configuration
$rzip->setTableName('zipcodes'); //optional, default is zips.
$rzip->setZipColumn('ZipCode'); //optional, default is zip.
$rzip->setLonColumn('Longitude'); //optional, default is lon.
$rzip->setLatColumn('Latitude'); //optional, default is lat.
//do the work
$rzip->setZipCodesInRange(); //call to initialize zip array
//zip code output, other processing can be done from this array.
$zipArray = $rzip->getZipCodesInRange();
$zipFinal = "";
foreach ($zipArray as $key => $value) {
$zipFinal .= "'" . $key . "',";
}
$zipFinal = substr_replace($zipFinal,"",-1);
//clear all other "AND" queries bellow
$where = "chd_dealers.ZipCode IN ($zipFinal)";
$dbQuery = mysql_query("SELECT
chd_dealers.Name,
chd_dealers.Address,
chd_dealers.City,
chd_dealers.State,
chd_dealers.ZipCode,
chd_dealers.Phone,
chd_dealers.`Web Address`,
chd_dealers.`e-mail`
FROM
chd_dealers
WHERE
".$where."
LIMIT ".$limit);
$countResult = mysql_num_rows($dbQuery);
if ($countResult == 0) {
$ret .= "<center><h4>Your zip code is outside of<br/> the program area.<br/><center> Please visit <br/> <center><a href=\"**********\" > The Honda Dealers of the Carolinas</a> <br/> to find a dealer near you.</h4>";
}
else {
$ret .= "<h3></h3>";
while ($dbRow = mysql_fetch_array($dbQuery)) {
// reset return variable
$retA = '';
// get distance
foreach ($zipArray as $key => $value) {
if ($dbRow['ZipCode'] == $key) {
$dis = $value;
}
}
$tempUrl = $dbRow['Web Address'];
if ($tempUrl[0] == 'w') {
$dbRow['Web Address'] = "http://".$dbRow['Web Address'];
}
Kelley
Last edited by kelley5454 : October 13th, 2008 at 01:01 PM.
Reason: Update
|