May 3, 2012
how to form select query by range
Question by bonny
hello i have a search engine for my site. i have two selection fields. i would like to give an example:
input_a: 3
input_b: 5
so the queries should look like:
if ( ($input_a == true) && ($input_b == false) ){
$filter_orders[] = " `col` LIKE '%$input_a%' ";
}
if ( ($input_a == false) && ($input_b == true) ){
$filter_orders[] = " `col` LIKE '%$input_b%' ";
}
if ( ($input_a == true) && ($input_b == true) ){
$filter_orders[] = " `col`= `col`>='%$input_a%' AND `col` = `col`<='%$input_b%' ";
now the problem is, that i dont know, if the last query is incorrect or not. the logic behind that will be that in case of my example the range between 3 and 5 should be found.
so 1,2 [3,4,5]
6,7,8…
if there is someone who could help me out i really would appreciate.
thanks a lot.
Answer by Starx
NO, sadly that is everything but correct. It should be something like this.
$filter_orders[] = " `col`>='%$input_a%' AND `col`<='%$input_b%' ";