Presto-X Posted April 9, 2007 Share Posted April 9, 2007 Hello guys, I could really use your help. I want to show a list of states at the top of a page, but I only want to show the ones that I have in my database. For example if there where only two states lets say Oregon and Idaho then the other 48 states would not show. $querystate=("SELECT state FROM `joomla_dealers`") or die(@mysql_error()); $resultstate=mysql_query($querystate); $numstate=mysql_numrows($resultstate); mysql_close(); $i=0; while ($i < $numstate) { $states=mysql_result($resultstate,$i,"state"); echo "<b><a href=\"index.php?state=$states\">$states</a></b> | "; $i++; } I have 2 links for Oregon and 1 for Idaho right now so when this loop runs it looks like this ID | OR | OR | the problem is that I only want the state to show up once how do I set my while loop to only echo out an item once? Link to comment https://forums.phpfreaks.com/topic/46231-solved-list-only-the-usa-states-in-a-query/ Share on other sites More sharing options...
btherl Posted April 9, 2007 Share Posted April 9, 2007 You can do: $querystate=("SELECT DISTINCT state FROM `joomla_dealers`") or die(@mysql_error()); Link to comment https://forums.phpfreaks.com/topic/46231-solved-list-only-the-usa-states-in-a-query/#findComment-224795 Share on other sites More sharing options...
Presto-X Posted April 9, 2007 Author Share Posted April 9, 2007 that did the trick, thank you so much btherl for your help Link to comment https://forums.phpfreaks.com/topic/46231-solved-list-only-the-usa-states-in-a-query/#findComment-224804 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.