Zeradin Posted June 9, 2010 Share Posted June 9, 2010 How does this work if i have $leads = mysql_query('SELECT * FROM leads l JOIN accountants a ON l.to_id = a.id'); $l = mysql_fetch_assoc($leads); and some of the columns have the same name on both tables, how do i mysql_fetch_assoc them out? $l['a.zip']; does not work Quote Link to comment https://forums.phpfreaks.com/topic/204331-mysql_fetch_assoc-and-joins/ Share on other sites More sharing options...
Psycho Posted June 9, 2010 Share Posted June 9, 2010 Well, you really shouldn't have fields with the same names between tables unless they are foreign keys. But, if you do, then you should only SELECT the fields that you want. If there is still a duplicate between tables and you need both values then SELECT them using a name. Selecting ONLY the fields you need SELECT l.field1, l.field2, a.field3, a.field4 FROM leads l JOIN accountants a ON l.to_id = a.id Selecting fields with the same name in multiple tables SELECT l.field1 as lead_field1, l.field2 as lead_field2, a.field1 as acct_field1, a.field2 as acct_field2 FROM leads l JOIN accountants a ON l.to_id = a.id Quote Link to comment https://forums.phpfreaks.com/topic/204331-mysql_fetch_assoc-and-joins/#findComment-1070119 Share on other sites More sharing options...
Zeradin Posted June 10, 2010 Author Share Posted June 10, 2010 thank you! Quote Link to comment https://forums.phpfreaks.com/topic/204331-mysql_fetch_assoc-and-joins/#findComment-1070451 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.