gaz Posted December 4, 2011 Share Posted December 4, 2011 Hello, I'm using a script that lists properties and allows users to search by given criteria i.e. cost, location and bedrooms etc. I'm attempting to modify my search form for a particular field, changing it from a text field to a dropdown. My table has a row titled, address_city, of course cities are duplicated in the table i.e. there may be 10 for London. I have the following code working but the dropdown displays every instance of the city - in this case 10. So please could someone tell me how to write this so each city is only listed once in my dropdown? <?php $sql = "SELECT * FROM ".$TABLES['properties']." ORDER BY title;"; $sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql); while ($row = mysql_fetch_assoc($sql_result)) { ?> <option value="<?php echo $row['id'];?>"><?php echo $row['address_city'];?></option> <?php } ?> Thanks Link to comment https://forums.phpfreaks.com/topic/252458-search-form-question/ Share on other sites More sharing options...
fenway Posted December 4, 2011 Share Posted December 4, 2011 DISTINCT address_city would help, instead of *. Link to comment https://forums.phpfreaks.com/topic/252458-search-form-question/#findComment-1294399 Share on other sites More sharing options...
gaz Posted December 4, 2011 Author Share Posted December 4, 2011 fenway, I can't thank you enough....Great forum, keep up the good work. Link to comment https://forums.phpfreaks.com/topic/252458-search-form-question/#findComment-1294422 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.