为工作构建可用性跟踪器。我对页面的管理部分感到有些困惑。我让它为单个用户更新或插入他的可用性(即单一形式的下拉框)。但是,对于主管页面,我可以使用while循环输出每个人的可用性。但是,我不知道如何知道哪个下拉框与特定用户/ ID相关联。
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if(isset($_POST['submit']))
{
$query = "SELECT * FROM availability WHERE week_start_date ='"
. $_SESSION['display_date'] . "';";
mysqli_query($db, $query) or die ('Error querying database');
$result = mysqli_query($db, $query);
// HERE IS WHERE I'M NOT SURE HOW TO UPDATE DATABASE
}
}
$query = "SELECT * FROM availability WHERE week_start_date ='"
. $_SESSION['display_date'] . "';";
mysqli_query($db, $query) or die ('Error querying database');
$result = mysqli_query($db, $query);
$num_rows = mysqli_num_rows($result);
while ($row = mysqli_fetch_array($result))
{
echo "<label>" . $row['pilot_id'] . "</label>";
echo "<br/>";
echo "<label>Monday:</label><br/>";
display_day("monday", $db);
echo "<br/>";
echo "<label>Tuesday:</label><br/>";
display_day("tuesday", $db);
echo "<br/>";
}
?>
display_data只是一个输出下拉框的函数。
function display_day($day, $db)
{
echo "<select name=" . $day ."> "
. "<option disabled selected value> -- select an option -- </option>";
$query = "SELECT * FROM availability_status";
mysqli_query($db, $query) or die ('Error querying database');
$result = mysqli_query($db, $query);
while ($row = mysqli_fetch_array($result))
{
echo "<option value='" . $row['status'] . "'>" . $row['status']
. "</option>";
}
echo "</select>";
}
我是否需要以某种方式将用户表中的主键附加到每个下拉框以了解如何更新表格?
免责声明:据我所知,这是一个草率的代码,不值得生产;我只需要运行一个原型。