#40940 [Com]: mysql_fetch_array returns different values for ASSOC and NUM
| From: | btherl at yahoo dot com dot au | Date: | Thu, 29 Mar 2007 03:29:04 +0000 |
| Subject: | #40940 [Com]: mysql_fetch_array returns different values for ASSOC and NUM | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-110899@lists.php.net to get a copy of this message | ||
ID: 40940
Comment by: btherl at yahoo dot com dot au
Reported By: dgk at visskiss dot org
Status: Open
Bug Type: MySQL related
Operating System: OS X
PHP Version: 5.2.1
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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