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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.