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 Quote Link to comment Share on other sites More sharing options...
fenway Posted December 4, 2011 Share Posted December 4, 2011 DISTINCT address_city would help, instead of *. Quote Link to comment 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. Quote Link to comment 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.