Switch statement - $sql2 default not performing

hi all

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.

But in my case $sql default is performed.

vineet

Those sections of code deal with setting two variables ( $sql and $sql2 ). Somewhere else it must determine which to use.

I Changed $sql2 variable to $sql.

now both codes are having same variable names.

still the problem persists the same

vineet

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?

there is nothing between the two codes


<?
$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*/
		}

?>

Then it looks like
if(isset($_REQUEST[‘sub_catg’]))
is giving you FALSE.

I would do something like the following to let you know if you have what you’re expecting.


if( isset( $_REQUEST['sub_catg'] ) ) {
  die( 'y ' . $_REQUEST['sub_catg'] );
} else {
  die( 'no' );
}