note 34970 deleted from function.mysql-fetch-array by didou
| From: | didou@php.net | Date: | Thu, 14 Aug 2003 06:31:08 +0000 |
| Subject: | note 34970 deleted from function.mysql-fetch-array by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-54123@lists.php.net to get a copy of this message | ||
Note Submitter: djburgie@hotmail.com
----
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).