johng Posted March 19, 2007 Share Posted March 19, 2007 I am currently working on a project where I need to put information from a sql statement into an array. Currently I can get one row into the array, but the rest aren't showing. I have checked, and all of the information is getting to the array, but I can only get one row to show up. Here's the code: while(($row = mysql_fetch_array($result))) { $info=array($count=>array('line1'=>$row["first_name"], 'line2'=>$row["last_name"], 'line3'=>$row["product"], 'line4'=>"\$".$row["date"])); $count++; } I'm trying to get this array to hold multiple rows from the sql statement, but when I display the array, I can only get one row out of it. Any help on this would be much appreciated. As always, thanks in advance! Link to comment https://forums.phpfreaks.com/topic/43369-solved-inserting-data-from-a-sql-database-into-an-array/ Share on other sites More sharing options...
per1os Posted March 19, 2007 Share Posted March 19, 2007 while(($row = mysql_fetch_array($result))) { $info[$count++]=array($count=>array('line1'=>$row["first_name"], 'line2'=>$row["last_name"], 'line3'=>$row["product"], 'line4'=>"\$".$row["date"])); } Link to comment https://forums.phpfreaks.com/topic/43369-solved-inserting-data-from-a-sql-database-into-an-array/#findComment-210618 Share on other sites More sharing options...
johng Posted March 19, 2007 Author Share Posted March 19, 2007 Thank you so much!!! I was stuck on this for way too long, and it was bugging the crap out of me! You are a lifesaver!!! Link to comment https://forums.phpfreaks.com/topic/43369-solved-inserting-data-from-a-sql-database-into-an-array/#findComment-210653 Share on other sites More sharing options...
Barand Posted March 19, 2007 Share Posted March 19, 2007 If you don't mind indexes of 'first_name', 'last_name' etc instead of 'line1', 'line2', 'line3' then this would suffice while(($row = mysql_fetch_assoc($result))) { $info[] = $row; } // view the info array echo '<pre>', print_r($info, true), '</pre>'; Link to comment https://forums.phpfreaks.com/topic/43369-solved-inserting-data-from-a-sql-database-into-an-array/#findComment-210685 Share on other sites More sharing options...
johng Posted March 23, 2007 Author Share Posted March 23, 2007 The main reason I used 'line1', 'line2', etc. is because it was being fed into another function, and that function was set up to use those field names. Basically it was way less complicated because I didn't want to fiddle with the other function. But thanks for the extra info! Link to comment https://forums.phpfreaks.com/topic/43369-solved-inserting-data-from-a-sql-database-into-an-array/#findComment-213724 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.