我有一些关于php left join的问题
php给我写了一个错误
您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 靠近'FROM ipb_topics t LEFT JOIN ipb_posts p ON p.topic_id = t.tid LEFT JOIN ipb_at'第12行
,代码是
$query = mysql_query("
SELECT
t.tid as tid,
t.title as title,
t.start_date as start_date,
t.title_seo as title_seo,
p.post as post,
a.attach_location as attach_location,
FROM ".$forum_prefix."topics t
LEFT JOIN ".$forum_prefix."posts p ON p.topic_id = t.tid
LEFT JOIN ".$forum_prefix."attachments a ON a.attach_rel_id = t.tid
GROUP BY t.tid
") or die(mysql_error());
答案 0 :(得分:2)
删除字段子句末尾的逗号。
答案 1 :(得分:0)
$query = mysql_query(" SELECT t.tid as tid, t.title as title, t.start_date as start_date, t.title_seo as title_seo, p.post as post, a.attach_location as attach_location FROM ".$forum_prefix."topics t LEFT JOIN ".$forum_prefix."posts p ON p.topic_id = t.tid LEFT JOIN ".$forum_prefix."attachments a ON a.attach_rel_id = t.tid GROUP BY t.tid ") or die(mysql_error());
试试这个!!不要忘记逃避您的数据。不要使用mysql_*
使用mysqli_*
或PDO
参考Link