title: Mysqli prepared statement: store rows in an array and loop through this array later
body: <p>I use a prepared statement to select rows in a database. Subsequently I would like to echo the individual rows using a while loop. This worked fine, until I tried using a new query within the execution of the while loop (this was necessary because I extract the userID, which I need to transform into a username. I did this by performing a query on the users table, but when I try this, my code doesn't run). I thought I might fix this by storing all the rows in an array, and later in my code loop through this array. However, I can't seem to figure out how to loop through all indices of this array and extract all fields of the row in each instance of the loop. </p>
  
  <p>Thanks a lot! Here is my code: </p>
  
  <pre><code>$results = array();
  
  $stmt = $db-&gt;prepare("SELECT admissionID,userID,description,link,postingdate,compensation FROM replies WHERE projectID=?");
  $stmt-&gt;bind_param('i',$projectID);
  $stmt-&gt;execute();
  $stmt-&gt;bind_result($admissionID,$userID,$description,$link,$postingdate,$compensation);
  while($row = $stmt-&gt;fetch()){
      $results[] = $row;
  }
  
  foreach($results as $result) {
      echo $result['admissionID'];
  }
  </code></pre>