你好,我的SQL
有问题。我会解决的。
$sql = "SELECT header,text,author FROM posts p LEFT JOIN users u ON u.username = p.author u.username as autorname";
//autor in table posts is ID
//in users is value ID = autor i need get username from users.
//username in users is varchar (name)
<? echo "" . $row["autorname"]. ""?>
任何数据均未显示
答案 0 :(得分:1)
您当前的查询甚至都不会编译,因为您最后有一个项目属于select。像您期望的那样,这样的事情可能会起作用:
SELECT header, text, u.username AS autorname
FROM posts p
LEFT JOIN users u
ON u.username = p.author
然后,具有给定行的以下回显应该起作用:
<? echo "" . $row["autorname"]. ""?>