Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding a sub sub category

    Hey guy's, This is my first time posting on these forums, Please be kind ^_^

    Is it possible to add a sub sub category to this code? If so could you give me a quick explanation on how to do that?

    Example:
    Main
    --Sub
    ---sub sub

    PHP Code:
    <?    echo ' <select name="catergory_id">
                 <option value="0">None</option>'
    ;
                 
    $sql2 $db->query("SELECT * FROM `{$SQL_Ext}_cats` WHERE `parentid` = '0' ORDER by `name`");
                 while (
    $row2 $db->fetch_assoc($sql2))
                 {
                   if (
    $row2['id'] == $theQuery['parentid'])
                    { 
                      echo 
    '<option value="'.$row2['id'].'" selected>'.$row2['name'].'</option>'
                    }
                    
                   elseif (
    $row2['id'] == $theQuery['id']) 
                    { 
                    
                    }
                    
                   elseif (
    $row2['id'] == 0
                    { 
                      echo 
    '<option value="0" selected>None</option>'
                    }
                   else
                    { 
                      echo 
    '<option value="'.$row2['id'].'">'.$row2['name'].'</option>'
                    }
                 }
                 echo 
    '</select>'
    ?>

  • #2
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    SELECT tags cannot have nested SELECT's. I mean, you could put them in there, but your browser wouldn't know how to handle it.

    Your only solution would be to display the nesting with some sort of indentation; whether that's a space or a '-'.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,476
    Thanks
    63
    Thanked 538 Times in 525 Posts
    Scroll to the bottom of this page and look at the thing called 'Forum Jump'.

    Right click on the page and view source. See how thats structured and then have a think about it in php.

    As for each item having a sub item (presumably you want this related in the database?) the way to do that is for each item to have a PARENT. Each item has its own id in the table right? - So its sub items PARENT would be set to that items id if you get my drift..
    I can't really think of anything to write here now...


  •  

    Posting Permissions

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