note 13732 added to ref.mysql.php
| From: | davey at shakedownwizards dot com | Date: | Sat, 30 Jun 2001 03:24:27 +0000 |
| Subject: | note 13732 added to ref.mysql.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-14802@lists.php.net to get a copy of this message | ||
The mysql_fetch_row function returns an array with numeric indices.
For example, a row from the query:
SELECT bookid,title,author FROM books
would look like:
$record[0]=3
$record[1]="A Farewell To Arms"
$record[2]="Ernest Hemingway"
The mysql_fetch_assoc function returns an array with indices that are the field names, like such:
$record["bookid"]=3
$record["title"]="A Farewell To Arms"
$record["author"]="Ernest Hemingway"
The mysql_fetch_array function returns an array with both kinds of indices, so this array looks
like:
$record[0]=3
$record["bookid"]=3
$record[1]="A Farewell To Arms"
$record["title"]="A Farewell To Arms"
$record[2]="Ernest Hemingway"
$record["author"]="Ernest Hemingway"
This is the reason for the "doubled" field output from the example.
Note that the mysql_fetch_array function has an optional parameter where you can specify the
indices.
So replacing the call:
mysql_fetch_array($result)
with:
mysql_fetch_array($result,MYSQL_NUM)
would be an identical fix to:
mysql_fetch_row($result)
Hope this helps!
http://www.php.net/manual/en/ref.mysql.php