Friday, 27 June 2014

Get Array Value in Combobox From MYSQL DataBase PHP

<?php
    @$conn = mysql_connect("localhost", "root", "");
    mysql_select_db("test", $conn);

    $query = "SELECT * from member";
    $result = mysql_query($query, $conn) or die(mysql_error());
    $num= mysql_num_rows($result);


    if ($num> 0) {
     while ($row = mysql_fetch_assoc($result)) {
        $array[] = array(
           'uid' => $row["uid"],
           'fname' => $row["fname"]
        );
     }
    }
    ?>

<form name="form" action="next.php" method="get">
        <select name="uid">
        <?php
        foreach($array as $value) {
          print("<option value=\"{$value['uid']}\">{$value['fname']}</option>");
        }
        ?>
        </select>
        <input type="submit" value="Send" />
</form>

No comments:

Post a Comment