I need help with structuring a mysql database query so that if a certain condition extists, then a further condition is applied to the "WHERE" clause.

This is my standard query:

SELECT * FROM products LEFT JOIN access ON product_id = access_product_id LEFT JOIN manufacturers ON product_manufacturer_id = manufacturer_id LEFT JOIN categories ON product_categories_id = categories_id LEFT JOIN feedback ON feedback_product_id = product_id AND feedback_member_id = '1' LEFT JOIN access_member ON product_id = member_product_id AND member_id = '1' WHERE 1 AND manufacturer_visible = 'Yes' AND 1174017600 <= product_created_date AND product_created_date >= UNIX_TIMESTAMP(DATE_SUB(CURDATE(),INTERVAL (4*7) DAY)) AND product_active = 'Yes' ORDER BY product_created_date DESC, product_id DESC LIMIT 0, 50

That is fairly straightforward.

Now, if the following condition exists (manufacturers table):

if manufacturer_restrictions = 'yes'

Then I would like the following condition also:

AND member_country IN(manufacturer_countries)

Can anybody help me to structure the main query to also include the above? If "manufacturer_restictions = 'no' ", then the manufacturer_countries column will be empty. It only contains data if restrictions have been set for a particular manufacturer.

Sonia

You can concate your query string conditionally

$query = "your query ";

if (your condition =true)
{
     $query=$query." your more condition";
}

execute_query($query);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.