bikey77
bikey77

Reputation: 6672

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 display 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!

Upvotes: 2

Views: 1956

Answers (1)

Chris Eberle
Chris Eberle

Reputation: 48795

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

Upvotes: 7

Related Questions