directly insert mysql_fetch_assoc() rows to array

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

directly insert mysql_fetch_assoc() rows to array

Post 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 ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

while($rows[] = mysql_fetch_assoc($res));
array_pop($rows);
return $rows;
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
Post Reply