我有两张桌子' lr_users'和' lr_ranks'具有以下表结构:
lr_users: user_id(pk),用户名,等级(fk),job_id(fk),date_joined
lr_ranks: rank_id(pk),名称
$qry= mysqli_query($con, "SELECT lr_users.username, lr_users.rank, lr_users.job_id, lr_users.date_joined lr_ranks.name AS rankname FROM lr_users
LEFT JOIN lr_ranks ON lr_users.rank = lr_ranks.rank_id")or die(mysqli_error($con));
$rows = mysqli_num_rows($qry);
以上是我的PHP代码,用于生成' LEFT JOIN'查询,但是当我运行它时,我收到以下错误:
您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以获得正确的语法,以便在' .name AS rankname FROM lr_users LEFT JOIN lr_ranks ON lr_users.rank = lr_ran'在第1行。
我做错了什么?
答案 0 :(得分:2)
语法错误(lr_users.date_joined
之前缺少逗号):
$qry= mysqli_query($con, "SELECT lr_users.username, lr_users.rank, lr_users.job_id, lr_users.date_joined, lr_ranks.name AS rankname FROM lr_users
LEFT JOIN lr_ranks ON lr_users.rank = lr_ranks.rank_id")or die(mysqli_error($con));
$rows = mysqli_num_rows($qry);
答案 1 :(得分:0)
如果您更清晰地格式化代码,则不会出现此类错误:
br.readLine();