City Finding Query

September 6th, 2009

Here is a MySQL (with PHP) query to search a city in a particular state that orders things so the most populous cities show up first.

//
//
select count(zip_code) as C_Star, city, state_prefix, zip_code from zip_code where UPPER(city) LIKE ".security_quotes(strtoupper("%".$_GET['q']."%"))."  and state_prefix = ".security_quotes(strtoupper($_GET['state']))." GROUP BY city ORDER BY C_Star DESC LIMIT 0,10

Searching a handy database of Zip Codes (free but may be out of date).

Leave a Reply

Back to mattsaul.com