database values in the combo box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LinDaOopD
    New Member
    • Feb 2007
    • 4

    database values in the combo box

    its easy to place an array values in the combo box.
    but i need to know how can i do it if i have to retrieve the values from a database.
    my platform is PHP MySql. please i need help :(
    combo box name=dep_list_s elected
    database name = dependency.
    if i choose value 'A' then the corresponding values of it that are stored in the table should appear in the combo box.
    if i choose another option then its respective values should be displayed.
  • hrubos
    New Member
    • Mar 2007
    • 2

    #2
    Originally posted by LinDaOopD
    its easy to place an array values in the combo box.
    but i need to know how can i do it if i have to retrieve the values from a database.
    my platform is PHP MySql. please i need help :(
    combo box name=dep_list_s elected
    database name = dependency.
    if i choose value 'A' then the corresponding values of it that are stored in the table should appear in the combo box.
    if i choose another option then its respective values should be displayed.

    So you can see it :
    Name:
    </td>
    <?php

    $query = "select last_name,first _name
    from student
    order by first_name ";
    $search_stu=mys ql_query($query )or die(mysql_error ());
    $name = array();

    //last name into array
    while ($rowN = mysql_fetch_ass oc($search_stu) )
    {
    array_push($nam e, $rowN["last_name"]);

    }
    ?>
    <?php //list of name ?>
    <td>
    <select name="name">
    <option value=" "></option>

    <?php foreach($name as $valueN) { ?>
    <option value="<?= $valueN ?>" <? if ($HTTP_POST_VAR S['last_name'] == $valueN){ echo "SELECTED";}?>> <?= $valueN ?></option>
    <? }

    ?>

    Comment

    Working...