guys if you notice in the code below query one is going to display it's content in th

Discussion in 'PHP' started by co.ador, Sep 9, 2009.

  1. #1
    guys if you notice in the code below query one is going to display it's content in the table below if user x set it. But I have different tables and layouts for each query. I want that when user x set
    if( isset($_GET['menu']) ){
    PHP:
    then user x will be taken to table 1 and if user x is set
    if( isset($_GET['subject']) ){
    PHP:
    then user x will be taken to table 2 in this moment both query when are set are taken to the same table.

    Can anybody help... thank you.
    
    <?php
    
    $submenu = false;
    
    // decide which is the correct query
    
    if( isset($_GET['menu']) ){
    
    $query = "SELECT id, submenus, image,
    FROM submenu
    WHERE
    id= " . (int) $_GET['menu']; 
    
    }
    elseif( isset( $_GET['subject']) ) {
    
    $query = "SELECT id, Subject, image,
    FROM subjects
    WHERE
    id= " . (int) $_GET['subject']; 
    
    }
    
    else{
    // if neither is set, do what?
    
    }
    
    // take a look at which was chosen
    echo $query ;
    
    // then deal with the query and display the table
    
    $result = mysql_query($query, $connection); 
      {
    
      echo '<table border="0" cellspacing="0" cellpadding="0" >
      <td></td>
    </table>';
    
    }
    
    ?>
    
    
    PHP:

     
    co.ador, Sep 9, 2009 IP
  2. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Sorry what do you exactly mean can't you just do:

    
    if( isset($_GET['menu']) ){
    //echo / redirect to table 1
    }
    else if( isset($_GET['subject']) ){
    //echo/redirect to table 2
    }
    
    PHP:
     
    wd_2k6, Sep 9, 2009 IP
  3. co.ador

    co.ador Peon

    Messages:
    120
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes it was so simple this what I think I want. I want that when a user set menu or subject then it takes user x to the table only inside the brackets of menu or subject not to display both tables together...

    I hope the code below achieved exactly that. let me know if it is correct

    
    if( isset($_GET['menu']) ){
    
    
    $query = "SELECT id, submenus, image,
    FROM submenu
    WHERE
    id= " . (int) $_GET['menu']; 
    
    
    echo $query ;
    
    $result = mysql_query($query, $connection); 
      {
    
      echo '<table border="0" cellspacing="0" cellpadding="0" >
      <td>different</td><td>different</td>
    </table>';
    
    
    }
    elseif( isset( $_GET['subject']) ) {
    
    $query = "SELECT id, Subject, image,
    FROM subjects
    WHERE
    id= " . (int) $_GET['subject']; 
    
    echo $query ;
    
    $result = mysql_query($query, $connection); 
      {
    
      echo '<table border="0" cellspacing="0" cellpadding="0" >
      <td></td>
    </table>';
    
    
    }
    PHP:
     
    co.ador, Sep 9, 2009 IP
  4. co.ador

    co.ador Peon

    Messages:
    120
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thank you WD it worked like you said man thank you...................

    
    <?php
    
    $submenu = false;
    $cat = isset($_GET['subject']) && is_numeric($_GET['subject'])?$_GET['subject']:null;
    $prod = isset($_GET['menu']) && is_numeric($_GET['menu'])?$_GET['menu']:null;
    $menu_type = isset($_GET['menu_type']) && is_string($_GET['menu_type'])?$_GET['menu_type']:null
    
    
    if ($prod){
    
    
    $query = "SELECT id, submenus, image,
    FROM submenu
    WHERE
    id= " . (int) $_GET['menu']; 
    
    
    echo $query ;
    
    $result = mysql_query($query, $connection); 
      {
    
      echo '<table border="0" cellspacing="0" cellpadding="0" >
      <td>different</td><td>different</td>
    </table>';
    
    
    }
    elseif( $cat) {
    
    $query = "SELECT id, Subject, image,
    FROM subjects
    WHERE
    id= " . (int) $_GET['subject']; 
    
    echo $query ;
    
    $result = mysql_query($query, $connection); 
      {
    
      echo '<table border="0" cellspacing="0" cellpadding="0" >
      <td></td>
    </table>';
    
    
    }
    ?>
    PHP:
     
    co.ador, Sep 9, 2009 IP