Jump to content

Zip Code Search


AE117

Recommended Posts

What I have is some PHP that does  a foreach statment to find all zip codes in a certain distance.

 

Heres what I need help with. I know the mySQL can use WHERE kkk IN (1,2,3,)  how ever how do I tell the php to format the foreach statment in a way that the SQL can use it???

 

Thanks

 

$zips = $z->get_zips_in_range('00501', 2, _ZIPS_SORT_BY_DISTANCE_ASC, true); 


if ($zips === false) echo 'Error: '.$z->last_error;
else {
   

   foreach ($zips as $key => $value) {
      echo "Zip code <b>$key</b> is <b>$value</b> miles away from <b>97214</b>.<br />";
  
   }
  
   
   echo "<br /><i>get_zips_in_range() executed in <b>".$z->last_time."</b> seconds.</i><br />";
}

Link to comment
https://forums.phpfreaks.com/topic/182590-zip-code-search/
Share on other sites

Once again I have answered my own question. I dont ever seem to get a reply here. But for anyone else that wants to know here you are.

 

To make the foreach (which is an array) echo into a format the sql can use you will need to take the array. In my case $zips

 

and then do this

 

$valuesz = implode(', ', $zips); 
echo $valuesz;

 

then You can use the valuesz in the mysql statment

 

valuesz will echo out    value, value, value        of course the values are what ever information you have in the database or whatever.

Link to comment
https://forums.phpfreaks.com/topic/182590-zip-code-search/#findComment-963720
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.