ID: 14091
Updated by: goba
Reported By: [EMAIL PROTECTED]
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] [EMAIL PROTECTED]
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