Mysql join and aliasing with mysql_fetch_object()
| From: | rkirk.com Mail | Date: | Thu, 02 Aug 2001 15:24:32 +0000 |
| Subject: | Mysql join and aliasing with mysql_fetch_object() | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-60925@lists.php.net to get a copy of this message | ||
I'm using a query similar to:
select tableA.*, tableB.* from tableA,
left join tableB ON tableA.keyfield = tableB.keyfield
When I then try to access the column "keyfield", after using
mysql_fetch_object() e.g.
$resultObject->keyfield
I get no value returned. What is the correct way to reference a field/column
that has the same name (as it's a primary and foreign key) on both tables?
Is there some syntax like:
$resultObject->tableA.keyfield ?
I've tried specifically aliasing the field on tableA e.g.
select tableA.*, tableA.keyfield AS myKeyField, tableB.* from tableA,
left join tableB ON tableA.keyfield = tableB.keyfield
and then using $resultObject->myKeyField but that doesn't seem to work
either.
I can't find any useful info/examples about this on the PHP site.
Also if I change the query to be:
select tableA.*, tableB.* from tableA, tableB
left join tableB ON tableA.keyfield = tableB.keyfield
adding the joined table to the FROM clause I get an error. Surely this is
the correct syntax and if anything my initial syntax should fail! Am I not
understanding this correctly or is my mySQL manual out of sync?
Please help
Thanks