zipp Posted May 2, 2008 Share Posted May 2, 2008 I am trying to get a sql column into a php array, but I am having no luck with it. Does anyone have a code to do this? Link to comment https://forums.phpfreaks.com/topic/103821-sql-column-php-array/ Share on other sites More sharing options...
mrdamien Posted May 2, 2008 Share Posted May 2, 2008 while($row = mysql_fetch_assoc($results)) { $table[] = $row; //or $column[] = $row['column_name']; } Link to comment https://forums.phpfreaks.com/topic/103821-sql-column-php-array/#findComment-531505 Share on other sites More sharing options...
benphp Posted May 2, 2008 Share Posted May 2, 2008 or while($row = mysql_fetch_assoc($results)) { $column = array($row['column_name']); } Link to comment https://forums.phpfreaks.com/topic/103821-sql-column-php-array/#findComment-531508 Share on other sites More sharing options...
mrdamien Posted May 2, 2008 Share Posted May 2, 2008 or while($row = mysql_fetch_assoc($results)) { $column = array($row['column_name']); } That would cause you to only have the last value in the column. Did you mean array_push($column, $row['column_name']) ? Link to comment https://forums.phpfreaks.com/topic/103821-sql-column-php-array/#findComment-531511 Share on other sites More sharing options...
benphp Posted May 2, 2008 Share Posted May 2, 2008 Really? Hrm - gotta remember that. Guess I need the brackets. Link to comment https://forums.phpfreaks.com/topic/103821-sql-column-php-array/#findComment-531513 Share on other sites More sharing options...
zipp Posted May 2, 2008 Author Share Posted May 2, 2008 while($row = mysql_fetch_assoc($results)) { $table[] = $row; //or $column[] = $row['column_name']; } Worked wonders Thanks. I tried the other one too, but he/she is right, its only the last value. Link to comment https://forums.phpfreaks.com/topic/103821-sql-column-php-array/#findComment-531540 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.