MySQL Simple join, duplicate field names
Posted: Wed Apr 18, 2007 7:36 am
Hi guys
This has been bugging me for a while but I've been unable to find the definitive answer.
I'm doing a simple join with the following query...
Where the 2 tables are related by a field called publication_id
Then I access the data by doing the following...
The problem is... as well as the publication_id field, both tables also have an id column which are auto_increment fields. These id fields are not related to each other.
The code above gets the $id value from the publications table, but how do I get $id to be the value from the adinserts table?
Where you have 2 fields with the same name, how do I access the first field?
Thanks
Ben
This has been bugging me for a while but I've been unable to find the definitive answer.
I'm doing a simple join with the following query...
Code: Select all
SELECT * FROM `adinserts`, `publications` WHERE adinserts.booking_id = 2 AND publications.publication_id = adinserts.publication_id ORDER BY publications.art_date ASC LIMIT 0, 100Then I access the data by doing the following...
Code: Select all
// LOOP THROUGH ADINSERTS
while ($adinserts = mysql_fetch_assoc($sql_result)) {
// GET DATA
$id = $adinserts['id'];
$publication_id = $adinserts['publication_id'];
$publication = $adinserts['publication'];
$web = $adinserts['web'];
$cancel_name = $adinserts['cancel_name'];
$cancel_stamp = $adinserts['cancel_stamp'];
...The code above gets the $id value from the publications table, but how do I get $id to be the value from the adinserts table?
Where you have 2 fields with the same name, how do I access the first field?
Thanks
Ben