开发者

Fetching by associative array

开发者 https://www.devze.com 2023-02-01 14:09 出处:网络
If you fetch the following data via an associative array in php: SELECT thread.id, thread.title, thread.content, author.username, author.id

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

精彩评论

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

关注公众号