title: How to implode a mysql query result array
body: <p>I am running an SQL query which returns 18 results then I try to implode them. When I use the implode command right after <code>mysqli_fetch_array</code> to implode the <code>mysqli_fetch_array</code> result, I get only the first element of the array. However when I do the same with a while loop it works fine. </p>
  
  <p>Here is my code: (it's simplified for ease of understanding)</p>
  
  <pre><code>$q = "SELECT id from sr WHERE m_id = '4';";
  $my_query = mysqli_query($conn, $q); 
  
  $records = mysqli_num_rows($my_query); 
  echo 'records=' . $records;
  
  $result = mysqli_fetch_array($my_query, MYSQLI_ASSOC);
  print_r ($result);
  
  $imploded_result = implode(",", $result);
  echo 'imploded_result=' . $imploded_result;
  </code></pre>
  
  <p>Here is what I get:</p>
  
  <pre><code>records=14
  Array ( [id] =&gt; 14 )
  imploded_result=14
  </code></pre>
  
  <p>Now, when I use a while loop instead of the implode(), I get the correct results:</p>
  
  <pre><code>$imploded_result = '';
  while ($result = mysqli_fetch_array($my_query, MYSQLI_ASSOC))
       $imploded_result .= $result['id'] . ',';
  echo 'imploded_result=' . $imploded_result;
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>imploded_result=14,21,24,27,28,30,31,32,37,152,155,154,156,157,158,159,181,196,
  </code></pre>
  
  <p>Thank you in advance!</p>