Double drop down menue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghjk
    Contributor
    • Jan 2008
    • 250

    #1

    Double drop down menue

    I want to use two drop down menus in my php application. All data should select from the database(Mysql) . Eg: 1st drop down(Fruit,Coun try,game) after selecting a item from the first drop down , second one should load perticular data from tha database. If i select Fruit then automatically load Mango,banana.et c to the second drop down. Could you please help me?
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    We are here to help programmers with their PHP problems. And we can only help when we can see and work on the code you have developed.

    So show it here and do not forget to enclose any code within the appropriate code tags!

    Ronald

    Comment

    • ghjk
      Contributor
      • Jan 2008
      • 250

      #3
      Originally posted by ronverdonk
      We are here to help programmers with their PHP problems. And we can only help when we can see and work on the code you have developed.

      So show it here and do not forget to enclose any code within the appropriate code tags!

      Ronald

      This is my first dropdown(Thease are hard coded. no need to select from the database)
      [HTML]<select name="name" id="name" >
      <option value="Select" selected="selec ted">Select</option>
      <option value="Fruit" >Fruit</option>
      <option value="Country" >Country</option>
      <option value="Game"> Game</option>
      </select> [/HTML]

      And second drop down should filled depend on the selected value in first dropdown.(get values from mysql database)

      Comment

      • sethupnr
        New Member
        • Sep 2007
        • 26

        #4
        [code=html]
        <!--
        ----------------------------
        here i juz worked in a localhost.
        database: demo1;
        table: demo_table;
        fields(demo_tab le)
        item varchar(20);
        list varchar(20);
        example table data( i here used a simple table structure u can use a well one):
        item list
        fruit Mango
        fruit banana
        Country India
        Country USA
        Country UK
        ----------------------------
        -->
        <html>
        <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <script type="text/javascript">
        function getItem(sel)
        {
        var itemCode = sel.options[sel.selectedInd ex].value;
        //alert(itemCode) ;
        var url= "http://localhost/onchange1.php?i tem="+itemCode;
        window.location =url;

        }
        </script>
        </head>

        <body>

        <form action="" method="post">
        <table>
        <tr>
        <td>Item </td>
        <td><select id="item" name="item" onchange="getIt em(this)">
        <option value="">Select </option>
        <option value="Fruit">F ruit</option>
        <option value="Country" >Country</option>
        </select>
        </td>
        </tr>
        <tr>
        <td>List </td>
        <td><select id="item_list" name="item_list " >
        <option value="">Select </option>
        <?php
        $i_code=$_REQUE ST['item'];

        $con = mysql_connect(" localhost","roo t","");
        mysql_select_db ("demo1",$co n);

        $query="select list from demo_table where item='$i_code'" ;
        $res=mysql_quer y($query);
        $num=mysql_num_ rows($res);
        for($i=0;$i<$nu m;$i++)
        {
        $data=mysql_fet ch_array($res);
        $v=$data[0].$i;
        echo "<option value='$data[0]'>".$data[0]."</option>";
        }
        ?>
        </select>
        </td>
        </tr>
        </table>
        </form>
        </body>
        </html>
        [/code]
        it is a simplest method, and also u can use AJAX.
        Last edited by Atli; Apr 5 '08, 08:33 PM. Reason: Added [code] tags.

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Hi sethupnr.

          Please use &#91;code] tags when posting your code examples. (See How to ask a question)

          &#91;code=ht ml] ...HTML code goes here... &#91;/code]

          Thank you.

          Comment

          • proremmy
            New Member
            • Nov 2011
            • 1

            #6
            i have categories,then under each category,i want a sub category,all from database for example,categor y sells,then sub items and this is a menue in an html page from database,can u help plz

            Comment

            Working...