#40940 [Bgs]: mysql_fetch_array returns different values for ASSOC and NUM
| From: | dgk at visskiss dot org | Date: | Thu, 29 Mar 2007 09:29:42 +0000 |
| Subject: | #40940 [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-110913@lists.php.net to get a copy of this message | ||
ID: 40940
User updated by: dgk at visskiss dot org
Reported By: dgk at visskiss dot org
Status: Bogus
Bug Type: MySQL related
Operating System: OS X
PHP Version: 5.2.1
New Comment:
Hi,
As you can see, I figured out a work around (write cleaner code)! But
I don't think this is as much a feature as an inconsistency. What
possible benefit could it be to have the numeric and assoc elements be
different?
Agreed, tje code should be cleaner, but you should just put the last
element in both assoc and numerical elements...
Thanks again!
Previous Comments:
------------------------------------------------------------------------
[2007-03-29 06:07:10] georg@php.net
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.
------------------------------------------------------------------------
[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