2012-09-03 29 views
0

我有一些問題用php左加入MySQL的左連接,錯誤的SQL語法

PHP寫我一個錯誤

您的SQL語法錯誤;檢查手冊中 對應於你的MySQL服務器版本正確的語法使用 附近 'FROM ipb_topics牛逼LEFT JOIN ipb_posts P於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

請不要使用'mysql_ *'功能,它棄用(見[*紅框*](http://php.net/manual/en/function。 mysql-query.php))並且容易受到sql注入的影響。使用[* PDO *](http://php.net/manual/en/book.pdo.php)或[* MySQLi *](http://php.net/manual/en/book.mysqli.php) 。 – alfasin

回答

2

刪除您的field子句末尾的逗號。

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