SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    622
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    switch statement - $sql2 default not performing

    hi all

    below is my switch function based on "choice" option selected (high/low)

    PHP Code:
    <?
    $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

    PHP Code:
    /*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

  2. #2
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Those sections of code deal with setting two variables ( $sql and $sql2 ). Somewhere else it must determine which to use.
    - Robert

  3. #3
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    622
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I Changed $sql2 variable to $sql.

    now both codes are having same variable names.

    still the problem persists the same

    vineet

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,069
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    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?
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  5. #5
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    622
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    there is nothing between the two codes

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

    ?>

  6. #6
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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.
    PHP Code:
    if( isset( $_REQUEST['sub_catg'] ) ) {
      die( 
    'y ' $_REQUEST['sub_catg'] );
    } else {
      die( 
    'no' );

    - Robert


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •