acctman Posted April 2, 2010 Share Posted April 2, 2010 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/197411-select-distinct-query/ Share on other sites More sharing options...
fenway Posted April 4, 2010 Share Posted April 4, 2010 Just add some ORs to the where clause -- not that this is particularly efficient. Quote Link to comment https://forums.phpfreaks.com/topic/197411-select-distinct-query/#findComment-1036773 Share on other sites More sharing options...
awebtech Posted April 4, 2010 Share Posted April 4, 2010 Maybe CONCAT(zc_city, ", ", zc_state, " ", zc_zip) is what you need ? Quote Link to comment https://forums.phpfreaks.com/topic/197411-select-distinct-query/#findComment-1036831 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.