'Display Data from MYSQL using PHP Dropdown
I need to display data from the 'Members' table based on the selected 'grad_date' from a drop down. I have been trying to do it for a while now but have struggled to get it to work. Currently I have:
<body>
<!-- HTML code can reside ABOVE and BELOW the starting and closing PHP tags -->
Select Grad Date
<?php
require_once 'login_name.php';
$db_server = mysqli_connect(...)
if (!$db_server) die("Unable to connect to MySQL: " . mysqli_error($db_server));
$sql = "SELECT DISTINCT grad_date FROM Members;";
//As we have already connected to the database, execute the query stored in the $sql variable
$result = mysqli_query($db_server, $sql);
//Check if the query was successfully executed: if the result is NOT FALSE
//More advanced logic can also be done based on success or failure
if($result)
{
//Create Drop-Down Menu
echo "<select name='Members'>";
while($row=mysqli_fetch_assoc($result))
{
//Store each SQL row's column name/value pair in a PHP variable
foreach($row as $key=>$value) ${$key}=$value;
//Load data onto drop-down menu
echo "<option value='$grad_date'>$grad_date</option>";
}
echo "</select>";
}
?>
<table>
<thead>
<th> member_id </th>
<th> member_first_name </th>
<th> member_last_name </th>
<th> team_id </th>
</thead>
<tbody>
</tbody>
</table>
<!-- HTML code can reside ABOVE and BELOW the starting and closing PHP tags -->
</body>
I have tried a couple different things to go from here but have not found any success. How can I do this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
