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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts

    interdependent select boxes

    hi,

    i have 2 select boxes on a page.what i want to do is when i select one option from 1st select box then related options will be displayed in 2nd select box.
    i have the following code to display both select box options from 2 mysql tables.

    or i have to go with javascript.any of your idea will be surely appreciated
    regards
    mrjameer


    PHP Code:
    if($_GET['action']=="create_subsubcategory")
    {

        if(isset($_POST['Submit']))
        {
        
        $category_name=$_POST['category_name'];
        $subcategory=$_POST['subcategory'];
        $subsubcat=$_POST['subsubcat'];

        
        $sql="INSERT INTO subsubcategories Values('','$category_name','$subcategory','$subsubcat')";
        $result=mysql_query($sql,$db_connect) or die (mysql_error());
    if($result)
            {
        echo "<center>NEW SUB SUB CATEGORY CREATED</center>";
            }
            else
            {
                echo "Sorry sub sub Category not created";
            }
        }
        else
        {

        
    ?>
    <br><br><br>
    <form name="fname" method="post" action="index.php?action=create_subsubcategory">
    <table width="350" border="1" cellspacing="0" cellpadding="0" align="center" class="border">
                    <tr>
                      <td>
                        <table width="350" border="1" cellspacing="1">
                          <tr align="center">
                            <td colspan="5" class="analyzer">Create Sub Sub Category</td>
                          </tr>
                          <tr align="center">
                           
                            
                           
                            <td class="analyzer"><select name="maincat"><option value=''>Select a Category....</option><?php

    $sql
    ="SELECT * FROM categories";
    $result=mysql_query($sql) or die (mysql_error());
    while(
    $newarray=mysql_fetch_array($result))
    {

       
    $category_name=$newarray['category_name'];

       
       echo
    "<option value='$category_name'>$category_name</option>";

    }

    echo
    "</select>";


        
    ?></td><td class="analyzer">MainCategory</td></tr>
                            <tr  align="center"><td class="analyzer"><select name="maincat"><option value=''>Select a Sub Category....</option><?php

    $sql
    ="SELECT * FROM subcategories";
    $result=mysql_query($sql) or die (mysql_error());
    while(
    $newarray=mysql_fetch_array($result))
    {

       
    $subcategory=$newarray['subcategory'];

       
       echo
    "<option value='$subcategory'>$subcategory</option>";

    }

    echo
    "</select>";


        
    ?></td><td class="analyzer">Sub Category</td></tr>
                            <tr  align="center"><td class="analyzer"><input type="text" name="subsubcat" value=""></td><td class="analyzer">Sub Sub Category</td></tr>
                            <tr>
                                                    <td class="analyzer" colspan="2" align="center"><input type="submit" name="Submit" value="Submit"></td>
                            

                          </table>
                          </table>

                        <?php

        
    }
        
    }

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Same question just asked:

    3 combobox linked doubt php


  •  

    Posting Permissions

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