View Single Post
Old 06-15-2009, 05:44 PM   #4 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

If you have conflicting columns then you will, unfortunately, need to specify them individually as in the code example.

To take your code as the example this time, you would have to specify explicitly that you would like the id from the tbl_products table, with your supplied alias, p. You would specify this by adding the following to your SELECT statement:

sql Code:
p.rn AS rn_id

Which, excluding your conditionals at the end of your MySQL statement above, would now be like so:

sql Code:
SELECT
    p.*,
    pd.*,
    p.rn AS rn_id
FROM
    tbl_products p,
    tbl_productsdetail pd

All your data is still returned, but the ID you require is now stored in rn_id, because rn_id is unique, whereas id is not unique to that particular table, and therefore overwritten.

So then to get the value you would do:

php Code:
echo $apshmrecords['rn_id'];
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote