// Start query, this is the basis of your query. Select everything from the table that contains the information on houses.
$sql = "SELECT * FROM house WHERE";
// Variable to determine whether anything has been added to the query, so must be 0 when starting
$num_queries = 0;
// Check whether the garden checkbox was selected. In the form you submitted, you have probably given the checkbox input a NAME and a VALUE. If this checkbox was checked, the $NAME (variable) equals that VALUE. So cb_garden represents the NAME and value_set_in_form the corresponding value.
if ($cb_garden==value_set_in_form)
{
// Check whether this is the first part to add to the query, if so, add without an AND and increase num_queries (to indicate that the first part has been added). I've set the query to NOT NULL, because I assume that you just want to check whether the column garden is filled (not search for a specific kind of garden).
if ($num_queries==0)
{
$sql .=" garden NOT NULL";
$num_queries++;
}
// if this was not the first part, the next part should start with AND so you will be searching on both a garden and (for instance) a pool
{
$sql .=" AND garden NOT NULL";
}
}
// Check whether the pool checkbox was selected
if ($cb_pool==value_set_in_form)
{
// If nothing was added to the query yet just add
if ($num_queries==0)
{
$sql .=" pool NOT NULL";
$num_queries++;
}
// otherwise, an AND must be included
else
{
$sql .=" AND pool NOT NULL";
}
}
I tried to explain the code as detailed as I could, I hope this solves your problem, if not, don't hestitate to reply!
One question by me: how did you know my nationality??
Groetjes,
Lara