Posted By

the_dev on 07/07/09


Tagged

mysql php


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

vali29


Turn MySQL results into an array, the proper way!


 / Published in: PHP
 

Here is the correct way to turn your mysql results into an array. Forget the other nonsense of useless code. Why type out this long code: "for($i = 0; $array[$i] = mysqlifetchassoc($result); $i++) ;" when you can accomplish the same thing with much less code.

  1. while($rows[] = mysqli_fetch_assoc($result));
  2. array_pop($rows); // pop the last row off, which is an empty row

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: ignace on September 13, 2009

while ($row = mysqlifetchassoc($result) && $rows[] = $row);

You need to login to post a comment.