通过关联数组获取

时间:2010-12-23 22:00:00

标签: php sql

如果您通过php中的关联数组获取以下数据:

SELECT thread.id, thread.title, thread.content, author.username, author.id
FROM thread INNER JOIN author
ON author_id = author.id

如何区分author.id和thread.id?

$threads = select_Query('SELECT thread.id, thread.title, thread.content, author.username, author.id
                         FROM thread INNER JOIN author
                         ON author_id = author.id', $link);

1 个答案:

答案 0 :(得分:2)

您可以使用列别名来解决列名歧义:

SELECT thread.id AS t_id, thread.title, thread.content, author.username, author.id AS a_id
FROM thread INNER JOIN author
ON author_id = author.id

然后分别引用PHP数组中的别名,分别为$row['t_id']$row['a_id']

相关问题