note 43942 added to function.mysql-fetch-object
| From: | q at rn2 dot php dot net | Date: | Fri, 09 Jul 2004 11:31:43 +0000 |
| Subject: | note 43942 added to function.mysql-fetch-object | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-72921@lists.php.net to get a copy of this message | ||
Some clarifications about previous notes concerning duplicate field names in a result set.
Consider the following relations:
TABLE_A(id, name)
TABLE_B(id, name, id_A)
Where TABLE_B.id_A references TABLE_A.id.
Now, if we join these tables like this: "SELECT * FROM TABLE_A, TABLE_B WHERE TABLE_A.id =
TABLE_B.id_A", the result set looks like this: (id, name, id, name, id_A).
The behaviour of mysql_fetch_object on a result like this isn't documented here, but it seems
obvious that some data will be lost because of the duplicate field names.
This can be avoided, as Eskil Kvalnes stated, by aliasing the field names. However, it is not
necessary to alias all fields on a large table, as the following syntax is legal in MySQL:
"SELECT *, TABLE_A.name AS name_a, TABLE_B.name AS name_b FROM TABLE_A, TABLE_B ...". This
will produce a result set formatted like this: (id, name, id, name, id_A, name_a, name_b), and your
data is saved. Hooray!
-q
----
Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-object.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43942
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43942&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43942&report=yes
Search -- http://master.php.net/manage/user-notes.php