title: Outputting multiple rows from database using MySQL and PHP
body: <p>I've written some simple php code designed to retrieve data from a database based on the session id. If the session ID is 1 then I query the database to find all entries with the UserID of 1 and then output them. </p>
  
  <p>This works to a certain extent, I can get the query to output the correct entries but for some reason it never outputs the most recent entry, instead it skips it and outputs the rest instead.</p>
  
  <p>My code is below, can anyone spot what I'm doing wrong? </p>
  
  <p>Thanks</p>
  
  <pre><code>$id = $_GET['id'];
  if ($id) 
  {
  $sql = "SELECT * FROM `forum_topics` WHERE `uid`='" . $id . "'";
  $res = mysql_query($sql) or die(mysql_error());
  
  if (mysql_num_rows($res) == 0) 
  {
      echo "You haven't got any adverts to display";
  } 
  else 
  {
      $row = mysql_fetch_assoc($res);
  
      echo "&lt;table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" width=\"100%\"&gt;\n";
  
      echo "&lt;tr align=\"center\"&gt;&lt;td class=\"forum_header\"&gt;Title&lt;/td&gt;&lt;td class=\"forum_header\"&gt;User&lt;/td&gt;&lt;td class=\"forum_header\"&gt;Date Created&lt;/td&gt;&lt;/tr&gt;";
  
      while ($row2 = mysql_fetch_assoc($res)) 
      {
          echo "&lt;tr align=\"center\"&gt;&lt;td&gt;&lt;a href=\"index.php?act=topic&amp;id=" . $row2['id'] . "\"&gt;" . s($row2['title']) . "&lt;/a&gt;&lt;/td&gt;&lt;td&gt;" . uid($row2['uid']) . "&lt;/td&gt;&lt;td&gt;" .                 $row2['date'] . "&lt;/td&gt;&lt;/tr&gt;";
      }
      echo "&lt;/table&gt;\n";
  
  
  
  }
  }
  </code></pre>