I'm using SQL Server 2008 R2
I'm a little stumped on how to properly coordinate a SQL query involving HTML selects as filters for the query. Now, I have no issues using the filters if I want something specific from both. (Querying a rental database and I want a blue boat, easy.) However, the issue comes in when I want all colors available to a specific vehicle. (a green, blue or red boat.)
The main point to focus on is the "All" options. The value of the options are blank. So, essentially, if I left the filters to "All" and "All", it should pull the entire database (I have other criteria I'll work in for my actual project, but this part is the tricky one for me.) Can I change that to something else better for the SQL statement?
JSFIDDLE
SQLFIDDLE
My current PHP syntax is simply this, but I can't use the "ALL"s in the selects.
Code: Select all
<?php
$color=$_POST['color'];
$type=$_POST['type'];
$sql = "SELECT * FROM dbo.rentals
WHERE (color=$color AND type=$type)";
?>Any help is appreciated!