title: while($stmt->fetch()) only looping once
body: <p>I'm using <code>while($stmt-&gt;fetch())</code> to loop though the results I get from a MySQL Query, and under certain conditions, I'm only getting one result.<br>
  I'm guessing this is becuase I've got 2 <code>$stmt</code>'s. but I thought this sort of thing was supported. I guess I'm making a rookie mistake, I've been used to non-prepared statements for too long!  </p>
  
  <pre><code>    $db = mysqlConnect();
      $stmt = $db-&gt;stmt_init();
      $stmt-&gt;prepare("SELECT id, uploadtype FROM uploads ORDER BY displayorder DESC");
      $stmt-&gt;execute();
      $stmt-&gt;bind_result($id, $uploadtype);
      while ($stmt-&gt;fetch()) {
          echo 'ID = ' . $id . '&lt;br /&gt;';
          if ($uploadtype == 'single') {
              $stmt-&gt;prepare("SELECT title, description FROM singles WHERE id = ?");
              $stmt-&gt;bind_param('i', $id);
              $stmt-&gt;execute();
              $stmt-&gt;bind_result($title, $description);
              $stmt-&gt;fetch();
              ?&gt;
              Title: &lt;? echo $title; ?&gt;&lt;br /&gt;
              Description: &lt;? echo $description; ?&gt;&lt;br /&gt;
              &lt;a href="edit.php?id=&lt;? echo $id; ?&gt;"&gt;Edit&lt;/a&gt;&lt;br /&gt;
              &lt;?
          }
      }
  </code></pre>
  
  <p>This only echo's one ID. I'm guessing this is the problem because when I use the following, I get all IDs echoed.</p>
  
  <pre><code>$db = mysqlConnect();
  $stmt = $db-&gt;stmt_init();
  $stmt-&gt;prepare("SELECT id, uploadtype FROM uploads ORDER BY displayorder DESC");
  $stmt-&gt;execute();
  $stmt-&gt;bind_result($id, $uploadtype);
  while ($stmt-&gt;fetch()) {
      echo 'ID = ' . $id . '&lt;br /&gt;';
  }
  </code></pre>
  
  <p>How can I get around this problem? I'm thinking I don't understand prepared statements quite right.<br>
  EDIT:<br>
  Now changed to this, but getting <code>invalid object or resource mysqli_stmt</code> on line starting <code>&lt;error&gt;</code>.  </p>
  
  <pre><code>$db = mysqlConnect();
      $stmt = $db-&gt;stmt_init();
      if (!$limit) {
          $stmt-&gt;prepare("SELECT id FROM uploads WHERE uploadtype = 'youtube' ORDER BY displayorder DESC");
      } else {
          $stmt-&gt;prepare("SELECT id FROM uploads WHERE uploadtype = 'youtube' ORDER BY displayorder DESC LIMIT 0, ?");
          $stmt-&gt;bind_param('i', $limit);
      }
      $stmt-&gt;execute();
      $stmt-&gt;bind_result($id);
      while ($stmt-&gt;fetch()) {
          $stmt2 = $db-&gt;stmt_init();
          $stmt2-&gt;prepare("SELECT title, description, url FROM youtube WHERE id = ?");
          &lt;error&gt;$stmt2-&gt;bind_param('i', $id);
          &lt;error&gt;$stmt2-&gt;execute();
          &lt;error&gt;$stmt2-&gt;bind_result($title, $description, $url);
          &lt;error&gt;while ($stmt2-&gt;fetch()) {
              $title = stripslashes($title);
              $description = stripslashes($description);
              $url = stripslashes($url);
              ?&gt;
              &lt;class id="item"&gt;
                  &lt;?
                  if ($gettitle) echo 'Title: ' . $title . '&lt;br/&gt;';
                  if ($getdescription) echo 'Description: ' . $description . '&lt;br /&gt;';
                  ?&gt;
                  &lt;iframe width="560" height="315" src="&lt;? echo $url; ?&gt;" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;
              &lt;/class&gt;&lt;br /&gt;
              &lt;?
          }
      }
  </code></pre>