The Midnighter Posted December 31, 2008 Share Posted December 31, 2008 I'm trying to create a Php array from a MySQL Table. Here's what I've got: $LOGIN_INFORMATION = array(); $result = mysql_connect($hostname,$user,$pass); mysql_select_db('info_moosehead'); $query = "SELECT admin_name FROM Portal_administrators"; $result = mysql_query($query); if( !$result) { echo mysql_error() . ": " . mysql_errno(); } while ( $row = mysql_fetch_array($result)) { echo $row; array_push($LOGIN_INFORMATION, $row); print_r($LOGIN_INFORMATION); echo "<br>"; } I'm noticing results like this: ArrayArray ( [0] => Array ( [0] => Airfire [admin_name] => Airfire ) ) ArrayArray ( [0] => Array ( [0] => Airfire [admin_name] => Airfire ) [1] => Array ( [0] => JAUGER [admin_name] => JAUGER ) ) ArrayArray ( [0] => Array ( [0] => Airfire [admin_name] => Airfire ) [1] => Array ( [0] => JAUGER [admin_name] => JAUGER ) [2] => Array ( [0] => JBARR [admin_name] => JBARR ) ) Which isn't what I expected at all, I'm looking for just the row "admin_name" to be pushed into this array, and yet that's what's going into the array.. Why?! Link to comment https://forums.phpfreaks.com/topic/139021-php-array-with-mysql/ Share on other sites More sharing options...
flyhoney Posted December 31, 2008 Share Posted December 31, 2008 <?php $LOGIN_INFORMATION = array(); $result = mysql_connect($hostname,$user,$pass); mysql_select_db('info_moosehead'); $query = "SELECT admin_name FROM Portal_administrators"; $result = mysql_query($query); if( !$result) { echo mysql_error() . ": " . mysql_errno(); } while ($row = mysql_fetch_array($result)) { $LOGIN_INFORMATION[] = $row['admin_name']; } foreach ($LOGIN_INFORMATION as $foo) { echo $foo . '<br />'; } ?> Link to comment https://forums.phpfreaks.com/topic/139021-php-array-with-mysql/#findComment-727096 Share on other sites More sharing options...
The Midnighter Posted December 31, 2008 Author Share Posted December 31, 2008 Oh... well, thank you Link to comment https://forums.phpfreaks.com/topic/139021-php-array-with-mysql/#findComment-727102 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.