Bug #14091 Updated: Problem with main example on the "MySQL Functions" page
| From: | goba@php.net | Date: | Sat, 17 Nov 2001 11:34:22 +0000 |
| Subject: | Bug #14091 Updated: Problem with main example on the "MySQL Functions" page | ||
| References: | 1 | Groups: | php.dev php.doc |
| Request: | Send a blank email to php-dev+get-70716@lists.php.net to get a copy of this message | ||
ID: 14091
Updated by: goba
Reported By: blakjak@webone.com.au
Old Status: Open
Status: Closed
Bug Type: Documentation problem
Operating System: RHL 6.1
PHP Version: 4.0.6
New Comment:
You are right, mysql_fetch_array() uses MYSQL_BOTH by default. I have just corrected the example,
and
added some comments, so it works OK...
Do not expect it to show up in a day, as the HTML
generation from XML is done daily.
Previous Comments:
------------------------------------------------------------------------
[2001-11-17 06:07:34] blakjak@webone.com.au
On the "LV. MySQL Functions" page of the PHP Manual, there is a piece of example code,
demonstrating how to connect to MySQL, send a query and output the result of that query. The part
I'm concerned about goes like this:
print "<table>\n";
while ($line = mysql_fetch_array($result)) {
print "\t<tr>\n";
while(list($col_name, $col_value) = each($line)) {
print "\t\t<td>$col_value</td>\n";
}
print "\t</tr>\n";
}
print "</table>\n";
When I reproduced this example, something went wrong. Specifically, every value was printed twice.
I'll elaborate on that - If my source table looked like this:
id name
---------
1 blah
2 foo
3 bar
Then the above code produced:
1 1 blah blah
2 2 foo foo
3 3 bar bar
My guess is that, because mysql_fetch_array supplies BOTH associative and numerical indexes, using
the "while(list = each)" format references two key/value pairs for every one.
When I used mysql_fetch_assoc instead of mysql_fetch_array, the example worked perfectly. I assume
that it would also work if you specified MYSQL_ASSOC or MYSQL_NUM for mysql_fetch_arry, but I
haven't tested it.
Feel free to email me if you need more detailed information.
Sincerely,
BJ
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=14091&edit=1