A
A
Abay Tazhigaliev2016-01-29 13:24:29
PHP
Abay Tazhigaliev, 2016-01-29 13:24:29

WHERE clause not working with subquery?

Here is the query code
$query = " SELECT article.*,
(SELECT COUNT(*) FROM comments WHERE comments.note_id = article.title_url AND comments.lang = '$lang') AS comments_count
FROM $table AS article";
I need to make a WHERE query after the $table variable $table.lang = '$lang'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Entelis, 2016-01-29
@webcoderpro

1) Passing anything to a request without escaping is considered unsafe.
2) in your case, you write as article, it is obvious that you need to use it in where

$query = " SELECT article.*,
(SELECT COUNT(*) FROM comments WHERE comments.note_id = article.title_url AND comments.lang = '$lang') AS comments_count
FROM $table AS article
WHERE article.lang = '$lang'";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question