Two queries;
SELECT *
FROM `products`
WHERE product_type = "" AND product_description LIKE "%a%";
and
SELECT *
FROM `products`
WHERE product_type = 10 AND product_description LIKE "%a%";
The product_type
value is full and works when it is correct (2md query).
But I also want it to work when the value is empty.
I also want a query to work like this, because there are a lot of columns;
SELECT *
FROM `products`
WHERE product_type = "" AND product_description LIKE "%a%" AND product_price = ""
Can you help me, please?
2
Answers
May be you get empty output because is not an empty string but null?
If it can be null check for white space.
Try
This is just builds up the
WHERE
clause dynamically, using the approach demonstrated in the example I suggested in the comments: