Jump to content

Php array with MySQL


The Midnighter

Recommended Posts

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

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.