below is my switch function based on “choice” option selected (high/low)
<?
$choice=$_REQUEST['choice'];
switch($choice) {
case 'high':
$sql = "select * from product_table where dealer_id=$dealer_id order by price desc LIMIT";
break;
case 'low':
$sql = "select * from product_table where dealer_id=$dealer_id order by price asc LIMIT";
break;
default :
$sql = "select * from product_table where dealer_id=$dealer_id";
break;
}
below is my code for switch function based on “sub_catg” + “choice” selected
/*switch for sub categories start*/
if(isset($_REQUEST['sub_catg']))
{
$sub_catg=$_REQUEST['sub_catg'];
switch($choice) {
case 'high':
$sql2 = "select * from product_table where dealer_id=$dealer_id and sub_catg=$sub_catg order by price desc";
break;
case 'low':
$sql2 = "select * from product_table where dealer_id=$dealer_id and sub_catg=$sub_catg order by price asc";
break;
default :
$sql2 = "select * from product_table where dealer_id=$dealer_id and sub_catg=$sub_catg";
break;
}
}
/* switch for sub categories ends*/
?>
The problem :
If “choice” is not selected but “sub_catg” is selected then $sql2 default query should be peformed.
Where does the query call occur, can you show us a more complete portion of the code, one that doesn’t leave us wondering what code may lie between the two segments you posted previously?
<?
$choice=$_REQUEST['choice'];
switch($choice) {
case 'high':
$sql = "select * from product_table where dealer_id=$dealer_id order by price desc LIMIT";
break;
case 'low':
$sql = "select * from product_table where dealer_id=$dealer_id order by price asc LIMIT";
break;
default :
$sql = "select * from product_table where dealer_id=$dealer_id";
break;
}
/*switch for sub categories start*/
if(isset($_REQUEST['sub_catg']))
{
$sub_catg=$_REQUEST['sub_catg'];
switch($choice) {
case 'high':
$sql = "select * from product_table where dealer_id=$dealer_id and sub_catg=$sub_catg order by price desc";
break;
case 'low':
$sql = "select * from product_table where dealer_id=$dealer_id and sub_catg=$sub_catg order by price asc";
break;
default :
$sql = "select * from product_table where dealer_id=$dealer_id and sub_catg=$sub_catg";
break;
}
}
/* switch for sub categories ends*/
$result=mysql_query($sql);
while($row = mysql_fetch_array($result))
{
/* display result*/
}
?>