我在php/mysql中运行一个连接几个表的查询,我试图在我的页面上显示结果.我的问题是所有表都具有相同的字段名称,当我尝试将内容显示为:时,会导致名称出现问题:
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'
Run Code Online (Sandbox Code Playgroud)
我试着回声,$row_result['table_name.field_name']但这不起作用.除了使用select description.name作为prodDescription等之外,还有其他方法吗?希望你能够做到以上几点,我赶紧写下来!
使用AS关键字.像这样:
SELECT A.column AS A_col, B.column AS B_col FROM A JOIN B ON A.key = B.key
然后你只需要引用A_col和B_col