Results 1 to 12 of 12

Thread: 2 combo box

  1. #1
    Join Date
    Mar 2004
    Location
    malaysia
    Posts
    96
    Rep Power
    190

    2 combo box

    i need to develope two combo box. each data from the combo box come from table (db).

    e.g. : combo box 1 - data come from 'level' table
    combo box 2 - data come from 'class' table.

    example:
    'level' table
    l_id level_name
    1 junior 1
    2 junior 2

    'class' table
    c_id l_id class_name
    1 1 daisy
    2 1 lily
    3 2 glory
    4 2 daisy

    So, if user choose junior 1 from combo box 1. Only class name with level id 1 will appear from combo box 2

    Please help me to solve this problem.... Thank you in advance

  2. #2
    Join Date
    Feb 2004
    Location
    Shah Alam
    Posts
    175
    Rep Power
    193
    The easiest way is to reload the page each time level combo box changes. As it loads, check what "level" had been chosen then query the database for "class" under the selected "level"

    I dont recomment javascript unless absolute nessary.

  3. #3
    Join Date
    Mar 2004
    Location
    malaysia
    Posts
    96
    Rep Power
    190
    You mean if have two level..then need two page
    e.g
    page1.php for level 1
    page2.php for level 2

    like that?

  4. #4
    Join Date
    Feb 2003
    Location
    Kluang, Johor
    Posts
    2,367
    Rep Power
    249
    you can do it in one page.

    when first time load the page, you load the combo box 1. Then, onChange at combo box1, submit the page(this will get the selected value) to its own.
    Then, check the combobox1 value... create combo box 2 from 'class' table according to the combo box1 value.

    Hope you can understand. Sorry for my poor explaination.

    btw, html got combo box meh? :P

  5. #5
    Join Date
    Feb 2004
    Location
    Shah Alam
    Posts
    175
    Rep Power
    193
    I think he means option object with more than one row ... ??

  6. #6
    Join Date
    Mar 2004
    Location
    malaysia
    Posts
    96
    Rep Power
    190
    mr lcf..do u have sample coding.. i couldnt get how it works...
    it is related with formhandler?

  7. #7
    Join Date
    Feb 2003
    Location
    Kluang, Johor
    Posts
    2,367
    Rep Power
    249
    hftey: I think she means list box/drop down list.

    Dear lina, I am sorry. I do not has sample coding. If you don't mind, please post your code here.

    We will have clearer picture if we know the codes and requirements.

  8. #8
    Join Date
    Mar 2004
    Location
    malaysia
    Posts
    96
    Rep Power
    190

    here is the coding

    dear lcf,

    <-------------------the form coding :------------------------------>

    <?php
    include "mode.php";
    ?>
    <title>New Registration</title>
    <body>
    <form method="post" name="form" action="register_process.php">
    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr valign="middle">
    <td width="19%">Level<br>
    <span class="normaltext2"><em>Tahap</em></span></td>
    <td width="36%">:
    <select name="s_grade">
    <option selected>Please Select</option>
    <?php
    $query_grade = "SELECT * FROM level";
    $result_grade = mysql_query($query_grade);
    while ($query_data = mysql_fetch_array($result_grade)) {
    ?>
    <option value="<?php print $query_data["level_name"];?>"><?php print $query_data["level_name"];?></option>
    <?php
    }
    ?>
    </select> </td>
    <td width="19%">Class<br>
    <span class="normaltext2">Kelas</span></td>
    <td width="26%">:
    <select name="s_class">
    <option selected>Please Select</option>
    <?

    $query_grade = "SELECT * FROM class order by class_name";
    $result_grade = mysql_query($query_grade);
    while ($query_data = mysql_fetch_array($result_grade)) {
    ?>
    <option value="<?php print $query_data["class_name"];?>"><?php print $query_data["class_name"];?></option>
    <?php
    }
    ?>
    </select></td>
    </tr>
    <tr>
    <td colspan ="4" align="center"><input class="inputbutton" type="submit" name="sumbit" value="Submit"> </td>
    </tr>
    </table>
    </form>
    </body>

    <---------------dump db----------------------------------------->

    -------'level table'

    CREATE TABLE `level` (
    `level_id` int(3) NOT NULL auto_increment,
    `level_name` varchar(50) NOT NULL default '',
    PRIMARY KEY (`level_id`)
    ) TYPE=InnoDB AUTO_INCREMENT=17 ;

    #
    # Dumping data for table `level_cec`
    #

    INSERT INTO `level` VALUES (1, 'Pre School 1');
    INSERT INTO `level` VALUES (2, 'Pre School 2');
    INSERT INTO `level` VALUES (3, 'Pre School 3');

    --------'class' table

    CREATE TABLE `class` (
    `class_id` int(3) NOT NULL auto_increment,
    `level_id` int(3) unsigned NOT NULL default '0',
    `class_name` varchar(50) NOT NULL default '',
    PRIMARY KEY (`class_id`,`level_id`)
    ) TYPE=InnoDB AUTO_INCREMENT=21 ;

    #
    # Dumping data for table `class`
    #

    INSERT INTO `class` VALUES (1, 1,'Melon');
    INSERT INTO `class` VALUES (2, 1,'Dew');
    INSERT INTO `class` VALUES (3, 1,'Sunflower');
    INSERT INTO `class` VALUES (4, 2,'Lily');
    INSERT INTO `class` VALUES (5, 2,'Carnation',);
    INSERT INTO `class` VALUES (6, 2,'Star');
    INSERT INTO `class` VALUES (7, 3,'Daisy');
    INSERT INTO `class` VALUES (8, 3,'Sunflower');
    INSERT INTO `class` VALUES (9, 3,'Rose');

  9. #9
    Join Date
    Feb 2003
    Location
    Kluang, Johor
    Posts
    2,367
    Rep Power
    249
    thank you. Is this your college tutorial/assignment?
    If you are waiting for full code, then I will disappointed you.

    There may be mistakes in my codes, try to correct them by yourselves.

    btw, where is the HEAD of your page? <HEAD></HEAD> ?

    Add this inbetween <HEAD></HEAD>:
    Code:
    <script language="JavaScript">
    function level_selected() {
    	document.location = "index.php?level=" + document.form.s_grade.value;	
    }
    </script>
    use:
    Code:
    <select name="s_grade" onChange="level_selected();">
    Replace:
    Code:
    <option value="<?php print $query_data["level_name"];?>"><?php print $query_data["level_name"];?></option>
    With:
    Code:
    <option value="<?php print $query_data["level_id"];?>"><?php print $query_data["level_name"];?></option>

    Add following before $query_grade = ...:
    PHP Code:
    $level $_GET['level'];
    if (
    $level != "") { 
    Replace:
    PHP Code:
    $query_grade "SELECT * FROM class order by class_name"
    With:
    PHP Code:
    $query_grade "SELECT * FROM class WHERE level_id = $level order by class_name"
    Remember to add one more } in the last
    PHP Code:
    <?php ?>
    Sorry if this confuse you. I am having headache now...

  10. #10
    Join Date
    Mar 2004
    Location
    malaysia
    Posts
    96
    Rep Power
    190

    tq

    lcf,

    thank you for the script..i will try to fix it

  11. #11
    Join Date
    Feb 2003
    Location
    Kluang, Johor
    Posts
    2,367
    Rep Power
    249

  12. #12
    Join Date
    Nov 2001
    Location
    Johor
    Posts
    772
    Rep Power
    233
    bleh buat kelas tuisyen kan LCF? makin kaya la haha
    I hate when:

    vBulletin Message:
    Sorry! The administrator has specified that users can only post one message every 60 seconds

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Search Engine Optimization by vBSEO 3.5.0 RC1 PL1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112