Posted By

Tate on 06/13/08


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

brent-man
Terion
vali29


Return array from MySQL query


 / Published in: PHP
 

  1. $result = mysql_query($query) or die($query);
  2.  
  3. $returnarray = array ();
  4. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  5. $returnarray[] = $row;
  6. }
  7.  
  8. return $returnarray;

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: kubak on June 24, 2008

hmm why not die(mysqlerror()) or die(mysqlerror().$query) getting the query but with the actual error message ? and there must be some reason for that line I just don't seem to see it - $returnarray = array ();

Posted By: the_dev on July 9, 2009

You can return the results as an array with one line: while($rows[] = mysqlfetchassoc($result)); Then array_pop($rows) and finally return $rows;

You need to login to post a comment.