nmrudolph Posted February 18, 2011 Share Posted February 18, 2011 I'm working on a website that uses a database to display the employees from different states. Below is the code I'm using and everything works great, but I can't figure out why all the results are getting posted twice. I'm trying to isolate just one state so we can have a different contact page for each state. Thanks for any help! Please let me know if you need more information. (I'm attaching a screenshot of what's happening as well.) <? include "public/public_common.php"; //Open Database Connection $db = open_db_connection(); $sql = "SELECT DISTINCT state_full = 'california' from users where active = 'Y' and show_on_contactus = 'Y'"; $results = mysql_query($sql, $db); if(!mysql_num_rows($results) == FALSE) { while($row = mysql_fetch_array($results, MYSQL_BOTH)) { echo "<ul id=\"directors\">\n"; $state_sql = "SELECT * from users where active = 'Y' and show_on_contactus = 'Y' and state_full = 'california' order by last_name"; $state_results = mysql_query($state_sql, $db); if(!mysql_num_rows($results) == FALSE) { while($state_row = mysql_fetch_array($state_results, MYSQL_BOTH)) { echo "<li>\n"; echo " <div class=\"fl dirimg\">\n"; if($state_row[photo] == "") { echo "<img border=\"0\" width=\"61\" height=\"85\" src=\"images/exe_placeholder.jpg\" alt=\"$state_row[first_name] $state_row[last_name]\" />\n"; } else { echo "<img border=\"0\" width=\"61\" height=\"85\" src=\"n2team/pictures/$state_row[photo]\" alt=\"$state_row[firstname] $state_row[last_name]\" />\n"; } echo " </div>\n"; echo " <span class=\"fr\">$state_row[first_name] $state_row[last_name]<br />\n"; echo " $state_row[title]<br />\n"; echo " $state_row[city], $state_row[state]<br />\n"; //echo " <a href=\"mailto:$state_row[email]\">$state_row[email]</a></span></li>\n"; } } echo "</ul>\n"; } } ?> [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/228123-mysql-results-doubling/ Share on other sites More sharing options...
Maq Posted February 18, 2011 Share Posted February 18, 2011 Please use tags in the future. Link to comment https://forums.phpfreaks.com/topic/228123-mysql-results-doubling/#findComment-1176425 Share on other sites More sharing options...
nmrudolph Posted February 21, 2011 Author Share Posted February 21, 2011 I'm guessing this won't apply to anyone else's code, but I did figure out how to fix the problem. I just had to change the first "SELECT DISTINCT * ...." to "SELECT DISTINCT 1 ..." Then it only displayed one group of results rather than the 2. Link to comment https://forums.phpfreaks.com/topic/228123-mysql-results-doubling/#findComment-1177773 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.