I have two tables, each with an “id” field. Here are the two tables:
news : id, authorid, datetime, body
authors : id, name
I have this select query:
SELECT * FROM news, authors WHERE (news.authorid = authors.id) ORDER BY news.datetime DESC;
Then, in PHP, I want to use id of the table news. I have this code:
while ($row = mysql_fetch_array($result))
{
// I want to take news.id, but it gives an error:
echo $row["news.id"]; // error: "Undefined index: news.id"
// And when I write only "id", it takes it of authors.
echo $row["id"]; // this id is authors.id, but I want news.id
}
Give them aliases
Or