title: while ($stmt->fetch()) not fetching all rows
body: <p>I am trying to display all recipes belonging to a logged in user using the while loop. I noticed that let's say, the user have 4 recipes, the first one will not be displayed, resulting in only 3 recipes appearing in the table. If the user have 3 recipes, the first one will not be displayed, resulting in only 2 recipes being displayed and so on.</p>
  
  <p>I had done my research and found out that this is because the first row will be ignored and hence it is not displayed.</p>
  
  <p>Is there anybody who can suggest what kind of corrections should i make to the loop to fix this problem?My codes involves displaying in a table, this is why i am still not able to figure out what should be done despite having looked at other questions which were already posted and answered.</p>
  
  <p>Many thanks!</p>
  
  <pre><code>&lt;?php
  
  // 0: Instead of hard coding I shall declare the value first
  
  $userid = $_SESSION['userid'];
  
  // 1: Connect to forumdb database
  
  $mysqli = new mysqli("localhost", "root", null, "recipedb") or exit("Error connecting to database");
  
  // 2: Prepare the statement to select recipename,recipeid,,imagefile belonging to the $userid from recipe table
  
  $stmt = $mysqli-&gt;prepare("Select recipename,recipeid,imagefile from recipe where userid=?");
  
  // 3: Bind the values
  
  $stmt-&gt;bind_param("s", $userid);
  
  // 4: Execute the statement
  
  $stmt-&gt;execute();
  
  // TODO 5: bind results into $recipename,$recipeid and $imagefile
  
  $stmt-&gt;bind_result($recipename, $recipeid, $imagefile);
  
  if ($stmt-&gt;fetch() == null) {
      echo "You did not have any recipes yet.&lt;br /&gt;";
  }
  else {
      echo "&lt;table style=width:100% &gt;";
      echo "&lt;tr&gt;&lt;td&gt;&lt;b&gt;Recipe&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Actions&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;";
  
      // Use while loop to fetch messages and put in a &lt;table&gt;
      // if
  
      while ($stmt-&gt;fetch()) {
          echo "&lt;tr&gt;";
  
          // 6: In 1st &lt;td&gt;, display recipename,recipeid,imagefile
  
          echo "&lt;td&gt;&lt;b&gt;$recipename&lt;/b&gt;&lt;br /&gt;&lt;b&gt;Recipe ID:&lt;/b&gt;$recipeid&lt;br /&gt; &lt;img src='images/$imagefile'    height='125' width='125'              &gt;   &lt;/td&gt;";
  
          // 7: In 2nd &lt;td&gt;, display View hyperlink
          // The View hyperlink links to recipedetails.php
          // The delete hyperlink links to deleterecipes.php
  
          echo "&lt;td&gt; &lt;a href='recipedetails.php?recipeid=$recipeid'&gt;View&lt;/a&gt;&amp;nbsp";
          echo "&lt;a href='deleteconfirmation.php?recipeid=$recipeid'&gt;Delete&lt;/a&gt;&amp;nbsp";
          echo "&lt;/tr&gt;";
      }
  
      echo "&lt;/table&gt;";
  }
  
  // 8: close the statement
  
  $stmt-&gt;close();
  
  // 9: close $mysqli
  
  $mysqli-&gt;close();
  ?&gt;
  </code></pre>