Is there any way to do something like this? Give the $variable a default value to make mysql return all the rows?
SELECT * FROM table WHERE column = ?;
bind_param('i', $variable);
It's not as stupid as it sounds... I need to filter content based on user input, so If user does not fill the input/select the value will be ALL
(or the correct answer). I wouldn't like to print php variables inside the prepare()
or make the default variable all the possible values. What is the correct way to do this?
I'm actually doing this:
if ($stmt = $mysqli->prepare(' SELECT t1.id, t2.*
FROM ' . $table . ' t1
INNER JOIN property t2 ON t2.id = t1.id
WHERE t2.use = ?
' . $city_cond
. $zone_cond . '
LIMIT ?, ?'))
But I wouldn't like to print inside the prepare()
so I ask if is there any way to do it with the bind_param()
and declaring a default value.