Jump to content

Select DISTINCT query


acctman

Recommended Posts

Hi I need help with querying multiple fields and formating the results. The user needs to query zc_city and zc_zip so what ever they type in needs to look in both fields and show results.

 

the formating results should be zc_city, zc_state zc_zip (ie NEW YORK, NY 10011). I know I need to added zc_state and zc_zip to the SELECT query but I dont know how to make the result format correctly. The coding below will start to show auto complete results for New York when the user starts typing. I would also like for it to show the same results if the user type in the zip code too 10011... and start showing New York, NY 10011

 

Thanks in advance

 

<?php
$q = strtolower($_GET["q"]);
if (!$q) return;

$sql = "SELECT DISTINCT zc_city AS locale FROM search_zipcodes WHERE zc_city LIKE '$q%'";

$rsd = mysql_query($sql);
while($rs = mysql_fetch_array($rsd)) {
$cname = $rs['locale'];
echo "$cname\n";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/197411-select-distinct-query/
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.