title: Returning Multiple Rows with MySqli and Arrays
body: <p>For the past two days or so I've been converting my functions to mysqli. I've run into a problem. I have a function that returns an array containing a row from the database. However, I want the array to contain multiple rows versus one. Also, how would I be able to echo out the individual posts. Here is my failed attempt that only displays one row in the array.</p>
  
  <pre><code>$mysqli = new mysqli("localhost", "user", "password", "database");   
  
  function display_posts ($mysqli, $user_id) {
  
     $fields = "`primary_id`, `poster_id`, `profile_user_id`, `post`";   
  
     $user_id = (int)$user_id;
  
     $query = "SELECT DISTINCT $fields FROM `posts` WHERE `profile_user_id` = $user_id 
     LIMIT 4";                    
  
     if ($result = $mysqli-&gt;query($query)) {
  
     $row = $result-&gt;fetch_assoc();
  
     return $row;
  
     $result-&gt;free();
  
     $stmt-&gt;close();
  
  }}
  </code></pre>
  
  <p>Here I am trying to display the data.</p>
  
  <pre><code>$user_id = 1;
  
  $posts = display_posts($mysqli, $user_id);
  
  //Not sure what to do with $posts. A While loop perhaps to display each post?
  </code></pre>