开发者

Fetching by associative array

If you fetch the following data via an associative array in php:

SELECT thread.id, thread.title, thread.content, author.username, author.id
FROM thread INNER JOIN author
ON开发者_高级运维 author_id = author.id

How can you differentiate between author.id and 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);


You can use column aliases to resolve column name ambiguities:

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

Then reference the aliases in your PHP array, as $row['t_id'] and $row['a_id'] respectively.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜