title: PHP Fetch data twice
body: <p>My function looks like that. </p>
  
  <pre><code> private function generateTree($courseID) {
          $q = "SELECT l.id, l.name AS lesson_name, c.name AS course_name FROM lessons AS l, courses AS c WHERE l.course_id=c.id AND c.id=?";
          $stmt = $this-&gt;db-&gt;prepare($q);
          $stmt-&gt;bind_param("i", $courseID);
          $stmt-&gt;execute();
          $stmt-&gt;store_result();
          if ($stmt-&gt;num_rows &gt; 0) {
              $stmt-&gt;bind_result($id, $lName, $cName);
              echo "&lt;li&gt; &lt;a href='#'&gt;$cName&lt;/a&gt; &lt;ul&gt;";
              while ($stmt-&gt;fetch()) &lt;====HERE!!!
                  echo "&lt;li&gt; &lt;a href='?course=$courseID&amp;lesson=$id'&gt; $lName &lt;/a&gt;&lt;/li&gt;";
              echo "&lt;/ul&gt; &lt;/li&gt;";
          }
      }
  </code></pre>
  
  <p>The problem is that I'm starting to fetch data inside a while condition, but I need it before the while, too. Can I fetch data twice? Any other suggestions?</p>