mysql_fetch_array to associative array
| From: | Andras Kende | Date: | Mon, 16 Jul 2007 14:41:28 +0000 |
| Subject: | mysql_fetch_array to associative array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-258923@lists.php.net to get a copy of this message | ||
Hello,
I use the following GetArray for returning an array from mysql results.
But having a hard time modifying it for returning a simple associative array
Like:
$conn->GetAssoc('SELECT id, name from manufacturers')
Array ( [2] => BMW [1] => MAZDA [9] => FORD )
function GetArray($query) {
$get = $this->Execute ( $query );
$row_id = 0;
while ( $row = mysql_fetch_array($get) ) {
foreach ( $row as $key => $value )
$result[$row_id][$key] = $value;
$row_id++;
}
mysql_free_result($get);
return $result;
}
function GetAssoc($query) {
$get = $this->Execute ( $query );
$row_id = 0;
while ( $row = mysql_fetch_array($get) ) {
?????????
}
mysql_free_result($get);
return $result;
}
I searched a lot but didn't find anything.
Thanks for any help :)
Andras