我的数据库中有两个表:
NEWS表格的栏:
id
user
带有列的USERS表:
我要执行此SQL:
SELECT * FROM news JOIN users ON news.user = user.id
当我在PHP中获得结果时,我想获取关联数组并通过获取列名$row['column-name']。如何获得具有相同列名的新闻ID和用户ID?
$row['column-name']
您可以为所选的列设置别名:
$query = 'SELECT news.id AS newsId, user.id AS userId, [OTHER FIELDS HERE] FROM news JOIN users ON news.user = user.id'