Optional where clause based on user input
-
Already using the ability to limit data based on user input following the example:
SELECT * FROM table WHERE fieldname = '<?php $_POST[formvariable] ?>'
But how to I add an optional clause based on whether a variable has a value or not.
For example:SELECT * FROM table WHERE pu.user_id = <?php $current_user->ID ?> AND fieldname = '<?php $_POST[formvariable] ?>'
If “formvariable” is not set, I would still like to return all the rows from table.
In other words, how to omit the “and” clause based on the value of “formvariable”?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Optional where clause based on user input’ is closed to new replies.