title: PHP While Loop Isn't Running Through All Selected Records From MySQL Database
body: <p>I have three tables underlying a blog: one for users, one for comments and one for threads.
  Not all the records retrieved are echoed by PHP and I think it may be to do with NULL values, for example on my memberlist page the following query retrieves data on four users:</p>
  
  <pre><code>SELECT COUNT(Topics.MemberID) AS NumberOfTopics, Users.id, 
      Users.FirstName, Users.LastName, Users.Joined 
  FROM Users LEFT JOIN Topics ON Users.id=Topics.MemberID GROUP BY Topics.MemberID
  </code></pre>
  
  <p>However if the last user(s) at the end of the list has no topics (NumberOfTopics = 0) they are not presented.
  If a user has a post count of 0 but they following record has a post count that isn't 0 the user is shown. Why?</p>
  
  <p>Here is the complete code:</p>
  
  <pre><code>$result = mysql_query("SELECT COUNT(Topics.MemberID) AS NumberOfTopics, ".
                        "Users.id, Users.FirstName, Users.LastName, Users.Joined ".
                        "FROM Users LEFT JOIN Topics ON Users.id=Topics.MemberID ".
                        "GROUP BY Topics.MemberID") 
               or die("Query failed with error: ".mysql_error());
  
  echo "&lt;table border='1'&gt;
  &lt;tr&gt;
  &lt;th&gt;Name&lt;/th&gt;
  &lt;th&gt;Joined&lt;/th&gt;
  &lt;th&gt;No. of posts&lt;/th&gt;
  &lt;/tr&gt;";
  
  while($row = mysql_fetch_assoc($result))
    {
    echo "&lt;tr&gt;";
    echo "&lt;td&gt;&lt;a href='/neuro/profile.php?userid=$row[id]'&gt;" . 
         $row['FirstName'] . " " . $row['LastName'] . "&lt;/a&gt;&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Joined'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['NumberOfTopics'] . "&lt;/td&gt;";
    echo "&lt;/tr&gt;";
    }
  echo "&lt;/table&gt;";
  
  mysql_close($con);
  </code></pre>
  
  <p>Thanks for reading!</p>