I have 2 variables in PHP (let's call them 'var1' and 'var2') and a sql command like this:
$sql = "SELECT `id`, `name` FROM `table` WHERE `var` = '{$var1}'"
if ($var2) {
$sql.= "AND `var`={$var2}"; }
Variable var1
it is always set, but var2 not. I want when var 2 is set to apply WHERE clause only for var2. This means that var2 is more restrictive than var1. How can i do this in SQL language.
WHERE ``var`` = '{$var2}'
? – Jay Blanchardmysql_
" functions warning either because we haven't enough to go on here. We don't know that$var1
and$var2
aren't the result of escaping things @MrTux – Jay Blanchard