note 19841 modified in function.mysql-fetch-array by torben
| From: | torben@php.net | Date: | Wed, 13 Mar 2002 00:52:32 +0000 |
| Subject: | note 19841 modified in function.mysql-fetch-array by torben | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-27696@lists.php.net to get a copy of this message | ||
If you perform a SELECT query which returns different columns with duplicate names, like this:
--------
$sql_statement = "SELECT tbl1.colA, tbl2.colA FROM tbl1 LEFT JOIN tbl2 ON tbl1.colC =
tbl2.colC";
$result = mysql_query($sql_statement, $handle);
$row = mysql_fetch_array($result);
--------
Then
$row[0] is equivalent to $row["colA"]
but
$row[1] is not equivalent to $row["colA"].
Moral of the story: You must use the numerical index on the result row arrays if column names are
not unique, even if they come from different tables within a JOIN. This would render
mysql_fetch_assoc() useless.
[Ed. note - or you could do the usual 'select tbl1.colA as somename, tbl2.colA as
someothername. . .' which would obviate the problem. -- Torben]
--was--
If you perform a SELECT query which returns different columns with duplicate names, like this:
--------
$sql_statement = "SELECT tbl1.colA, tbl2.colA FROM tbl1 LEFT JOIN tbl2 ON tbl1.colC =
tbl2.colC";
$result = mysql_query($sql_statement, $handle);
$row = mysql_fetch_array($result);
--------
Then
$row[0] is equivalent to $row["colA"]
but
$row[1] is not equivalent to $row["colA"].
Moral of the story: You must use the numerical index on the result row arrays if column names are
not unique, even if they come from different tables within a JOIN. This would render
mysql_fetch_assoc() useless.
http://www.php.net/manual/en/function.mysql-fetch-array.php