From: [EMAIL PROTECTED] Operating system: RHL 6.1 PHP version: 4.0.6 PHP Bug Type: Documentation problem Bug description: Problem with main example on the "MySQL Functions" page
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 bug report at: http://bugs.php.net/?id=14091&edit=1 -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]