2017-06-29 95 views
0

這裏是我的查詢:語法錯誤或訪問衝突

SELECT qa.id, 
     qa.subject, 
     qa.category cat, 
     qa.keywords tags, 
     qa.body_html, 
     qa.amount, 
     qa.author_id author, 
     qa.visibility, 
     qa.date_time, 
     COALESCE(u.reputation, 'N') reputation, 
     COALESCE(CONCAT(u.user_fname, ' ', u.user_lname), 'ناشناس') name, 
     COALESCE(u.avatar, 'anonymous.png') avatar, 

    (SELECT COALESCE(sum(vv.value),0) 
    FROM votes vv 
    WHERE qa.id = vv.post_id 
    AND 15 = vv.table_code) AS total_votes, 

    (SELECT COALESCE(sum(vt.total_viewed),0) 
    FROM viewed_total vt 
    WHERE qa.id = vt.post_id 
    AND 15 = vt.table_code 
    LIMIT 1) AS total_viewed 
FROM qanda qa 
INNER JOIN qanda_tags qt ON qt.qanda_id = qa.id 
INNER JOIN tags ON tags.id = qt.tag_id 
LEFT JOIN users u ON qa.author_id = u.id 
AND qa.visibility = 1 
WHERE qa.type = 0 tags.name = :t 
ORDER BY qa.date_time DESC 
LIMIT :j, 
     11; 

它拋出這個錯誤:

Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'tags.name = ? ORDER BY qa.date_time desc LIMIT ?,11' at line 18 in C:\xampp\htdocs\myweb\others\questions.php:136 Stack trace: #0 C:\xampp\htdocs\myweb\others\questions.php(136): PDO->prepare('SELECT qa.id, q...') #1 C:\xampp\htdocs\myweb\others\questions.php(293): questions->index('tags.name = :t1', '\tINNER JOIN qan...') #2 C:\xampp\htdocs\myweb\application\other.php(21): questions->tagged() #3 C:\xampp\htdocs\myweb\index.php(149): require_once('C:\xampp\htdocs...') #4 {main} thrown in C:\xampp\htdocs\myweb\others\questions.php on line 136

我真的不知道有什麼問題。該錯誤消息說它接近tags.name = ?,但它完全適合我。

有沒有人有什麼問題?

回答

2

更換

WHERE qa.type = 0 tags.name = :t 

WHERE qa.type = 0 AND tags.name = :t 
+0

良好的漁獲物。爲什麼我沒有看到這一點。不管怎樣,謝謝你 –

相關問題