note 34970 added to function.mysql-fetch-array

From: Date: Wed, 13 Aug 2003 18:31:23 +0000
Subject: note 34970 added to function.mysql-fetch-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-54098@lists.php.net to get a copy of this message
This is interesting at least...and annoying at worst. With mysql_fetch_array (defaulted or explicitly set to MYSQL_BOTH) using results from a query which pulls from 2+ tables where a field in two or more tables (tested with 2) have a column with the same name, the associative array side will always take and return the last column it finds with the given name, while the numeric side will keep adding values until the end of time. What that garble means is that $query = "SELECT * FROM tbl1, tbl2"; where both tables are defined as: tbl1: columnone, columntwo tbl2: columntwo, columnthree $result = mysql_query($query); $row = mysql_fetch_array($result); $row[0] == 'tbl1 columnone value'; $row[1] == 'tbl1 columntwo value'; $row[2] == 'tbl2 columntwo value'; $row[3] == 'tbl2 columnthree value'; while $row['columnone'] == 'tbl1 columnone value'; $row['columntwo'] == 'tbl2 columntwo value'; $row['columnthree'] == 'tbl2 columnthree value'; If more tables are added with same-named fields I assume more numeric fields will be added and the associative fields will continue to be overridden. If you modify the select statement to EXPLICITLY ask for tbl1.columnone that may allow you to pull out the values associatively (is that a word?) but I have not tested that. As always, case-sensitivity applies because that is how MySQL works (yes, MySQL, like all SQL should be, is case sensitive when it comes to names of dbs, tables, fields, etc). ---- Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-array.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34970 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34970&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34970&report=yes

« previous php.notes (#54098) next »