john mossel
john mossel

Reputation: 2156

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);

Upvotes: 0

Views: 99

Answers (1)

BoltClock
BoltClock

Reputation: 724452

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.

Upvotes: 2

Related Questions