function create_select($menuname)
{
    echo "<select name= '{$menuname}'>\n";
    $dbc = connect_to_db("jed");
    $query = "select ID, lastname, firstname from student";
    $result = perform_query($dbc, $query);
    while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
        $firstname = $row['firstname'];
        $lastname = $row['lastname'];
        $id = $row['ID'];
        if (isset($_GET[$menuname]) && $_GET[$menuname] == $id) {
            echo "<option value = '{$id}' selected> {$firstname}  {$lastname} </option>\n";
        } else {
            echo "<option value = '{$id}'> {$firstname}  {$lastname} </option>\n";
        }
    }
    echo "</select>";
    disconnect_from_db($dbc, $result);
}
Beispiel #2
0
function displayform($currentstudent = "")
{
    $dbc = connect_to_db("jed");
    $query = "select ID, lastname, firstname from student";
    $result = perform_query($dbc, $query);
    echo "<form method=\"get\">\n\t\t  <select name=\"studentmenu\">";
    while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
        $firstname = $row['firstname'];
        $lastname = $row['lastname'];
        $id = $row['ID'];
        if ($id == $currentstudent) {
            echo "<option value=\"{$id}\" selected>{$firstname} {$lastname}</option>\n";
        } else {
            echo "<option value=\"{$id}\">{$firstname} {$lastname}</option>\n";
        }
    }
    echo "</select>\n\t\t<input type=\"submit\" name=\"formsubmitted\" value=\"go\" />\n\t\t</form>";
    disconnect_from_db($dbc, $result);
}
<?php

include 'dbconn.php';
?>
<!DOCTYPE html>
<head>
<title>Selecting Multiple Records</title>
</head>
<body>
<?php 
$dbc = connect_to_db("jed");
$query = "select lastname, firstname from student";
$result = perform_query($dbc, $query);
echo "<ul>\n";
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    $firstname = $row['firstname'];
    $lastname = $row['lastname'];
    echo "<li>{$firstname}  {$lastname} </li>\n";
}
echo "</ul>\n";
disconnect_from_db($dbc, $result);
?>
</body>
</html>