I’m trying to create filtered search with opportunity to select prices from to
HTML:
<select id="selectbox2" name="from">
<option value="x">Choose</option>
<option value="500">500</option>
<option value="1000">1000</option>
<option value="1500">1500</option>
<option value="2000">2000</option>
<option value="2500">2500</option>
<option value="3000">3000</option>
<option value="4000">4000</option>
</select>
<select id="selectbox2" name="to">
<option value="x">Choose</option>
<option value="500">500</option>
<option value="1000">1000</option>
<option value="1500">1500</option>
<option value="2000">2000</option>
<option value="2500">2500</option>
<option value="3000">3000</option>
<option value="4000">4000</option>
</select>
PHP:
if ((isset($_GET['features'])) && ($to!='x') && ($from!='x') ){
$result = mysql_query("SELECT * FROM baldas WHERE kategorija = '$id2'
AND $features = 1 AND kaina BETWEEN '$from' AND '$to'
ORDER BY pavadinimas_lt LIMIT $offset, $rowsPerPage") or die(mysql_error());
}
elseif ((isset($_GET['features'])) && ($to!='x') && ($from=='x') ){
$result = mysql_query("SELECT * FROM baldas WHERE kategorija = '$id2'
AND $features = 1 AND kaina BETWEEN '$from' AND 500000
ORDER BY pavadinimas_lt LIMIT $offset, $rowsPerPage") or die(mysql_error());
}
elseif ((isset($_GET['features'])) && ($to=='x') && ($from!='x') ){
$result = mysql_query("SELECT * FROM baldas WHERE kategorija = '$id2'
AND $features = 1 AND kaina BETWEEN 0 AND '$to'
ORDER BY pavadinimas_lt LIMIT $offset, $rowsPerPage") or die(mysql_error());
}
The part if ((isset($_GET['features'])) && ($to!='x') && ($from!='x') ) is working fine, but when to or from is equal x is giving no results. Where is the problem?
This part:
is wrong, because there you check BETWEEN 0 AND ‘$to’. And you check $to for ‘x’ so that turns out wrong ( BETWEEN 0 AND ‘X’). I’d recommend echo’ing the SQL Queries. You can easily fix this by changing the conditional parameters.