#40940 [Opn->Bgs]: mysql_fetch_array returns different values for ASSOC and NUM
| From: | georg@php.net | Date: | Thu, 29 Mar 2007 06:07:10 +0000 |
| Subject: | #40940 [Opn->Bgs]: mysql_fetch_array returns different values for ASSOC and NUM | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-110901@lists.php.net to get a copy of this message | ||
ID: 40940
Updated by: georg@php.net
Reported By: dgk at visskiss dot org
-Status: Open
+Status: Bogus
Bug Type: MySQL related
Operating System: OS X
PHP Version: 5.2.1
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
You should write cleaner code and avoid duplicate column names in
associative arrays.
Previous Comments:
------------------------------------------------------------------------
[2007-03-29 03:29:04] btherl at yahoo dot com dot au
This is not a bug. From the manual:
"If two or more columns of the result have the same field names, the
last column will take precedence. To access the other column(s) of the
same name, you must use the numeric index of the column or make an alias
for the column. For aliased columns, you cannot access the contents with
the original column name."
In this case, the last "id" will be from the right table, whereas index
0 will be from the left table.
------------------------------------------------------------------------
[2007-03-29 00:55:42] dgk at visskiss dot org
Description:
------------
mysql_fetch_array returns different values for MYSQL_NUM and
MYSQL_ASSOC
Reproduce code:
---------------
$query = "SELECT table1.*, table2.* FROM table1 LEFT JOIN table2 ON
table1.id = table2.id WHERE table1.data='foo'";
$result = mysql_query($query);
$row=mysql_fetch_array($result);
$row['id'] = NULL; //(there is no corresponding row for left join)
$row[0] = 2 //there is a value for id from table1...
Expected result:
----------------
same value for associative and numerical element
Actual result:
--------------
assoc picks up one value, num another...
seems only to occur for left joins where there is a null row for join
criteria....
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=40940&edit=1