This is where I started from:
include("ZipCodesRange.class.php");
//initialization, pass in DB connection, from zip code, distance in miles.
$zip = new ZipCodesRange($db,'98303',50);
//do the work
$zip->setZipCodesInRange(); //call to initialize zip array
//zip code output, other processing can be done from this array.
$zipArray = $zip->getZipCodesInRange();
And I found this:
function format_sql_array($array)
{
$SQLstring = "";
foreach($array as $item)
{
$SQLstring .= "'$item',";
}
$SQLstring = rtrim($SQLstring, ",");
$SQLstring = str_replace("'',", "", $SQLstring);
return $SQLstring;
}
With...
$my_array = $zipArray;
$sql_array = format_sql_array($my_array);
$query_Dealers = "SELECT * FROM Dealers WHERE Zip IN($sql_array)";
Obviously, this isn't the exact SELECT code but you get the idea.
The problem I'm having now it print_r($zipArray) results in:
Array ( [98002] => 26.04 [98004] => 39.45 [98005] => 40.52 [98006] ......
I've tried:
$my_array = $zipArray[0]; //or $my_array = $zipArray[1];
$sql_array = format_sql_array($my_array);
$query_Dealers = "SELECT * FROM Dealers WHERE Zip IN($sql_array)";
And nothing. It's a bit of a newbie question but I've tried numerous ways of making this work.