Dysan Posted January 1, 2008 Share Posted January 1, 2008 Hi, I have a table that contains a list of people's first names. This table contains duplicate names. Using PHP, how do I retrieve one instance of each of the names, stored in the "Names" column, and add them to a drop-down box? Quote Link to comment https://forums.phpfreaks.com/topic/83928-retrieve-names/ Share on other sites More sharing options...
forumnz Posted January 1, 2008 Share Posted January 1, 2008 Do you want to retrieve specific names? If so, all users should have an ID column, that way you can SELECT WHERE id='$id' Otherwise, I dont know. Good Luck! Quote Link to comment https://forums.phpfreaks.com/topic/83928-retrieve-names/#findComment-427121 Share on other sites More sharing options...
Psycho Posted January 1, 2008 Share Posted January 1, 2008 This page has a tutorial on EXACTLY what you are asking: http://www.webdevelopersnotes.com/tutorials/sql/online_mysql_guide_the_distinct_keyword.php3 Quote Link to comment https://forums.phpfreaks.com/topic/83928-retrieve-names/#findComment-427122 Share on other sites More sharing options...
Dysan Posted January 1, 2008 Author Share Posted January 1, 2008 Brillient! Cheers. So I need to you the distinct clause. But, how do I put the retrieve names into a drop-down box? Quote Link to comment https://forums.phpfreaks.com/topic/83928-retrieve-names/#findComment-427134 Share on other sites More sharing options...
Northern Flame Posted January 1, 2008 Share Posted January 1, 2008 try: <?php // Connect To Database $query = mysql_query("SELECT name FROM table"); echo "<select name=names>\n"; while($row = mysql_fetch_array($query)){ echo "<option value='". $row['name'] ."'>". $row['name'] ."</option>\n"; } echo "</select>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/83928-retrieve-names/#findComment-427137 Share on other sites More sharing options...
Dysan Posted January 1, 2008 Author Share Posted January 1, 2008 how do I change it to a list box? Quote Link to comment https://forums.phpfreaks.com/topic/83928-retrieve-names/#findComment-427143 Share on other sites More sharing options...
Northern Flame Posted January 1, 2008 Share Posted January 1, 2008 you mean like this? <?php // Connect To Database $query = mysql_query("SELECT name FROM table"); echo "<select multiple name=names>\n"; while($row = mysql_fetch_array($query)){ echo "<option value='". $row['name'] ."'>". $row['name'] ."</option>\n"; } echo "</select>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/83928-retrieve-names/#findComment-427145 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.