PHP display results of join query
I'm running a query in php/mysql that joins several tables and I'm trying to display the results on my page. My problem is that all tables have the same field names, leading to an abgitious name problem when I try to displa开发者_C百科y the content as:
echo $row_result['name']; // this would be i.e. the name of the product but I also have another table 'descriptions' in which I also have a field 'name'
I tried echoing $row_result['table_name.field_name']
but this won't work.
Is there another way, apart from using select description.name as prodDescription etc?
Hope you can make sence of the above, I wrote it in a hurry!
Use the AS
keyword. Like this:
SELECT A.column AS A_col, B.column AS B_col FROM A JOIN B ON A.key = B.key
Then you would just reference A_col and B_col
精彩评论