In the original post, Nikko50 wanted to get the actual name of the key and the value of the key, then he wanted to insert them into his array statement as keyname->keyvalue. When I use mysql_fetch_array($result, MYSQL_ASSOC), I get they keynames set to variables, but not the keynames themselves. In other words, I get "$fred", but not "fred". What I was trying to figure out is how do I get "fred". Does this make better sense?
nikko50 was "trying to populate the "newArray" with the field name as the key and the field value as the value".
Suppose we have a database table named User with the fields name, phone, and address. If we want to populate an array with the field names name and phone and get the field value as the value using the MySQL API, we would write:
$result = mysql_query("SELECT name, phone FROM User");
$user = mysql_fetch_assoc($result);
Now $users has the data we wanted, e.g., equivalent to:
$user = array('name' => 'John', 'phone' => '12345');
If we wanted to extend this to an array of multiple rows from the result set, we would then write:
$result = mysql_query("SELECT name, phone FROM User");
$users = array();
while ($row = mysql_fetch_assoc($result)) {
$users[] = $row;
}
Then $users would be equivalent to say:
$users = array(
array('name' => 'John', 'phone' => '12345'),
array('name' => 'Jane', 'phone' => '67890')
);
Note that mysql_fetch_assoc($result) is equivalent to mysql_fetch_array($result, MYSQL_ASSOC).