Bug #16029 Updated: Feature Request on mysql_fetch_array()

From: Date: Thu, 25 Apr 2002 08:34:21 +0000
Subject: Bug #16029 Updated: Feature Request on mysql_fetch_array()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-5943@lists.php.net to get a copy of this message
ID: 16029 Updated by: mderk@yandex.ru Reported By: mjm@porter.appstate.edu Status: Closed Bug Type: MySQL related Operating System: Linux 2.4 (intel) PHP Version: 4.1.2 New Comment: That is not true. All the fields are returned from the server, and one can fetch the field name, if he knows the number of the field in the returned row. And when php_mysql_fetch_hash() comes into play, it uses add_assoc_stringl() to place the result fields into array or object that returned by mysql_fetch_array() and friends. Unfortunately, add_assoc_stringl() in this case simply rewrites the value of the field colA, coming from tbl1 with the value of the field with the same name coming from tbl2, because they would have the same associative key in the resulting hash. I saw some clever client libraries that avoid this rewrite - they verify first if the field with the name of the current field is present in the resulting hash/recordset, and then, if it is true, append a number to the current field name to store it with the new key. E.g., ELECT tbl1.colA, tbl2.colA FROM tbl1 LEFT JOIN tbl2 ON tbl1.colB = tbl2.colB could end up in array with keys 'colA' for tbl1.colA and 'colA_1' for tbl2.colA. Previous Comments: ------------------------------------------------------------------------ [2002-03-12 20:09:14] torben@php.net The data is returned from the server like that. What you can do is: 'select tbl1.colA as tbl1_colA, tbl2.colA as tbl2_colA. . .' Torben ------------------------------------------------------------------------ [2002-03-12 19:55:38] mjm@porter.appstate.edu When you SELECT two columns from different tables with the same column name in a JOIN, you cannot use column names is associative array keys. It would be really nice when you did something like this: ------- $result = mysql_query("SELECT tbl1.colA, tbl2.colA FROM tbl1 LEFT JOIN tbl2 ON tbl1.colB = tbl2.colB"); $row = mysql_fetch_array($result); ------- if you could then do something like this: ------- $mydata1 = $row["tbl1.colA"]; $mydata1 = $row["tbl2.colA"]; ------- With the current behavior, you may only access the second array element with its numerical index. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=16029&edit=1

« previous php.bugs (#5943) next »