title: Search for city state zip
body: <p>So i already have a database of locations of every city, state, zip.</p>
  
  <p>I am currently working on how to do a search and get results of surrounding zip codes x miles away, and have run into some trouble.</p>
  
  <p>I successfully have the search working for you to type in the zip code, since it is a predefined value. But am having trouble with results of a city, state. Currently it only works if you type in just the city name ex "Chicago"... But Does not work if you type in "Chicago, IL".</p>
  
  <p>Here is the code for the $_GET of the search form, searchval</p>
  
  <p>Please Help!</p>
  
  <pre><code>$searchval = $mysql-&gt;escape_data($_GET['searchval']);
  if (!empty($searchval))
  {
      if(preg_match("~\d{5}~", $searchval)) {
      $zip = $searchval;
      }
      else {
      $city = $searchval;
      }
  } else
  {
      $error .= "&lt;div id='Error'&gt;Please enter zip&lt;/div&gt;";
      $zip = false;
  }
  </code></pre>
  
  <p>Below is the code that actually takes the $zip or $city and gets the surrounding zip codes. if you enter a zip code, it works successfully. If you enter just a city name, it works successfully. If you enter "Chicago, IL" it does not work.</p>
  
  <pre><code>       &lt;?php
     //if user entered a city ex. "Chicago"
     if(isset($city)) {
      $q = 'SELECT City, State, ZipCode FROM zipcodes WHERE City like "'. $city .'%" ORDER BY ZipCode ASC Limit 0,10'; 
      $result = $mysql-&gt;query($q);
      $row = mysqli_fetch_array($result);
      $zip = $row[2];
      if(mysqli_num_rows($result) != 1) {
      echo"Did you mean...&lt;br /&gt;";
      while($row = mysqli_fetch_array($result)) {
      echo "&lt;a href='" .$_SERVER['PHP_SELF'] . "?searchval=".$row[2]."&amp;miles=".$miles."'&gt;" . $row[0] . " " . $row[1] . " " . $row[2] . "&lt;/a&gt;&lt;br /&gt;";
      }
      }
      }
      $zcr = new ZipCodesRange($mysql,$zip,$miles);
      $zcr-&gt;setNewOrigin($zip);
  
      //if user entered a zip code ex. "08026"
      if($zcr-&gt;validateZipCode($zip)) {
      $citystate=$zcr-&gt;getCityState($zip);
      echo "Zip Codes Within " . $miles ." miles of " . $citystate[0] . ", " . $citystate[1] . " " . $zip;
      }
  
      $zcr-&gt;setZipCodesInRange();
      $zipArray = $zcr-&gt;getZipCodesInRange();
      asort($zipArray);
      $z = implode(",", array_keys($zipArray));
  
          $q = "SELECT * FROM " . TBL_PUBS . " WHERE zip IN ($z) AND( status = 'Pending' OR status = 'Active' )";
          $result = $mysql-&gt;query($q);
          while ($row = $result-&gt;fetch_object()) {
          $lonlat=$zcr-&gt;getLonLat($row-&gt;zip);
          $distance = $zcr-&gt;calculateDistance($lonlat[1], $lonlat[0], $zip);
      ?&gt; 
  </code></pre>