jaxdevil Posted May 20, 2008 Share Posted May 20, 2008 I am generating a drop down box dynamically based on the entries in the database. I want the drop down to only show one line for each unique entry. Like if there are 8 entries that say Jacksonville I want it to just show 1 entry for Jacksonville, etc. So the output will not show any duplicates. Anyone now how I can modify this to display each entry just once? <SELECT NAME="location"> <OPTION VALUE="NONE">-----Select Product Location---- <?php $sql = "SELECT * FROM locations"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { ?> <OPTION VALUE="<?=$row['locations']?>"><?=$row['locations']?> <?php } ?> </SELECT> Quote Link to comment https://forums.phpfreaks.com/topic/106526-solved-display-only-one-row-of-each-of-the-same-text-in-output/ Share on other sites More sharing options...
rhodesa Posted May 20, 2008 Share Posted May 20, 2008 $sql = "SELECT locations FROM locations GROUP BY locations"; Quote Link to comment https://forums.phpfreaks.com/topic/106526-solved-display-only-one-row-of-each-of-the-same-text-in-output/#findComment-546059 Share on other sites More sharing options...
jonsjava Posted May 20, 2008 Share Posted May 20, 2008 <?php $sql = "SELECT DISTINCT(`locations`) FROM locations"; Quote Link to comment https://forums.phpfreaks.com/topic/106526-solved-display-only-one-row-of-each-of-the-same-text-in-output/#findComment-546061 Share on other sites More sharing options...
rhodesa Posted May 20, 2008 Share Posted May 20, 2008 Not sure if it's true or not, but I've been told GROUP BY is faster then DISTINCT Quote Link to comment https://forums.phpfreaks.com/topic/106526-solved-display-only-one-row-of-each-of-the-same-text-in-output/#findComment-546063 Share on other sites More sharing options...
jonsjava Posted May 20, 2008 Share Posted May 20, 2008 DISTINCT is the standard way. Quote Link to comment https://forums.phpfreaks.com/topic/106526-solved-display-only-one-row-of-each-of-the-same-text-in-output/#findComment-546067 Share on other sites More sharing options...
jonsjava Posted May 20, 2008 Share Posted May 20, 2008 must be tired: <?php $sql = "SELECT DISTINCT `locations` FROM locations"; Quote Link to comment https://forums.phpfreaks.com/topic/106526-solved-display-only-one-row-of-each-of-the-same-text-in-output/#findComment-546070 Share on other sites More sharing options...
jaxdevil Posted May 21, 2008 Author Share Posted May 21, 2008 You are all da man!! Quote Link to comment https://forums.phpfreaks.com/topic/106526-solved-display-only-one-row-of-each-of-the-same-text-in-output/#findComment-546258 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.