Page 1 of 1

directly insert mysql_fetch_assoc() rows to array

Posted: Tue Aug 24, 2004 11:37 pm
by anjanesh

Code: Select all

function SomeFunction()
 {
    $arrRow=array();
    $res=mysql_query("SELECT Id FROM `table1`");
    while ($row=mysql_fetch_assoc($res))
     {
     	$arrRow[]=$row['Id'];
     }
    return $arrRow;
 }
Anyway to directly have all rows of $row inserted into $arrRow ?

Posted: Tue Aug 24, 2004 11:50 pm
by feyd

Code: Select all

while($rows[] = mysql_fetch_assoc($res));
array_pop($rows);
return $rows;

Posted: Wed Aug 25, 2004 12:08 am
by anjanesh
The method is similar - looping.
I was thinking in terms of getting the resultant row directly into an array without actually getting the rows one by one.

Posted: Wed Aug 25, 2004 12:20 am
by feyd
you mean like fetching the entire column... hmmm.. kinda dangerous, if they even supported it.. which I don't see any mysql functions php gives access to.. it could easily suck up a LOT of memory very fast..