What I would like to do is to run a where clause only if a certain value (that will be loaded dynamically) = a certain value. For example
IF ('<=' == '$dynamic_value') THEN WHERE...
Is this possible? (the $dynamic value will either be <=, or >=)
In other words, I would like to use the where clause only when certain value happens or invoke.
You can use a
CASEexpression in theWHEREclause like so:If
$dynamic_valuedoes not equal to either>=or<=, theELSE 1will be used by theWHEREclause instead – which is basically like having noWHEREclause at all (and return all records).Since it seems like you’re using PHP and the value of
$dynamic_valuecan only be>=or<=, you can just insert the parameter directly like:Of course if coming from user-input, then be sure you’re checking whether
$dynamic_valueis either>=or<=.