HTML
<label>0-500
<input type="checkbox" name="price[]" value="1" />
</label>
<label>500-1000
<input type="checkbox" name="price[]" value="2" />
</label>
<label>1000-2000
<input type="checkbox" name="price[]" value="3" />
</label>
PHP CODE
//parameter like [0 => "2", 1 => "3"]
function getQuery($form) {
$query = "SELECT * FROM yourtable WHERE false";
if (in_array("1", $form)) {
$query. = " OR price >= 0 AND price <= 500";
}
if (in_array("2", $form)) {
$query. = " OR price >= 500 AND price <= 1000";
}
if (in_array("3", $form)) {
$query. = " OR price => 1000 AND price <= 2000";
}
return $query;
}
OR
//parameter like [0 => "500-1000", 1 => "1000-2000"]
function getQuery($form) {
$query = "SELECT * FROM yourtable WHERE false";
foreach($form as $range) {
$ranges = explode("-", $range);
$from = ranges[0];
$to = ranges[1];
$query. = " OR BETWEEN $from AND $to";
}
return $query;
}
<label>0-500
<input type="checkbox" name="price[]" value="1" />
</label>
<label>500-1000
<input type="checkbox" name="price[]" value="2" />
</label>
<label>1000-2000
<input type="checkbox" name="price[]" value="3" />
</label>
PHP CODE
//parameter like [0 => "2", 1 => "3"]
function getQuery($form) {
$query = "SELECT * FROM yourtable WHERE false";
if (in_array("1", $form)) {
$query. = " OR price >= 0 AND price <= 500";
}
if (in_array("2", $form)) {
$query. = " OR price >= 500 AND price <= 1000";
}
if (in_array("3", $form)) {
$query. = " OR price => 1000 AND price <= 2000";
}
return $query;
}
OR
//parameter like [0 => "500-1000", 1 => "1000-2000"]
function getQuery($form) {
$query = "SELECT * FROM yourtable WHERE false";
foreach($form as $range) {
$ranges = explode("-", $range);
$from = ranges[0];
$to = ranges[1];
$query. = " OR BETWEEN $from AND $to";
}
return $query;
}
No comments:
Post a Comment