Question:
How to Add one more WHERE condition in PHP ?
Mark
2015-07-29 11:37:05 UTC
I am new to PHP . I am editting a php script . This script has a function that selects many values from a table but I need this Script to SELECT values from those rows only whose country_id = 100 only .
Can you please add this condition for me into following script (to select only values whose row has country_id = 100 } )
...............

$sql = "SELECT
c.category_id,
c.parent_id,
cd.name,

(SELECT COUNT(*) FROM `" . DB_PREFIX . "category` cc WHERE cc.parent_id = c.category_id) as children

FROM `" . DB_PREFIX . "category` c
LEFT JOIN `" . DB_PREFIX . "category_description` cd
ON (c.category_id = cd.category_id)
WHERE c.parent_id = " . (int)$parent_id . "
AND c.status = 1

AND cd.language_id = " . (int)$this->config->get('config_language_id') . "
ORDER BY c.sort_order, cd.name ASC";
Three answers:
Jeff P
2015-07-29 11:39:19 UTC
Just add it anywhere in the WHERE clause:



AND c.status = 1 AND country_id = 100 AND cd.language_id = ...
?
2015-07-30 00:01:07 UTC
One of the most HORRIBLE query I have seen for the last 20 years...

When you have to use "JOIN", your database is badly structured.

When you have to use functions in a query, your access to db is drafty to say the least.

Jeff P gave you the answer, but you will hit similar problems all the way through your development.
yesman
2015-07-31 00:48:32 UTC
You should use where statement inside if statement


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...