0
votes

Here is my query:

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;

And it throws this error:

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

I really don't know what's the problem. The error message says its near tags.name = ?, but it's totally right to me.

Does anybody what's the problem?

1

1 Answers

2
votes

Replace

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

with

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