
February 7th, 2012, 07:53 PM
|
 |
SQL Consultant
|
|
Join Date: Feb 2003
Location: Toronto Canada
|
|
you're on the right track
three suggestions --
first, string literals have to be enclosed in quotes, so it's 'y' not y
second, ditch the unnecessary backticks
finally, start your WHERE clause with WHERE 1=1, and then you can AND whichever of the additional conditions apply
Code:
$sql_command = "SELECT * FROM tx_snakes WHERE 1=1"
if ($cbrown == 'checked') { $sql_command += " AND browns = 'y'" }
if ($cblack == 'checked') { $sql_command += " AND blacks = 'y'" }
if ($ctan == 'checked') { $sql_command += " AND tans = 'y'" }
disclaimer: i don't do php and this isn't the php forum
|