Jump to content

Recommended Posts

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.