我需要关系:一个与时间相关,一个在提交表单后所选时间进入。我正在尝试创建一个应该排序的下拉菜单。如果已经占用的时隙仍应显示在下拉列表中,但是已禁用。例如。 9,10:占用,11 ......等等。 此时占用的插槽位于菜单的底部。我怎样才能实现,它们应该出现在应有的位置。 到目前为止,这是我的代码:
$query = "SELECT stunde FROM zeiten WHERE buchbar = 2 and
NOT EXISTS (SELECT *
FROM raumbuchung
WHERE zeiten.stunde =
raumbuchung.zeitanfang and belegt = 'belegt');
SELECT zeitanfang, belegt from
raumbuchung where belegt = 'belegt'";
echo "Beginn der Veranstaltung: ";
echo "<select name='time' id='t1'>";
if (mysqli_multi_query($conn, $query)) {
do {
if ($result = mysqli_store_result($conn)) {
while ($row = mysqli_fetch_assoc($result)) {
if ($row[belegt]) {
echo "<option value=$row[zeitanfang] disabled>$row[zeitanfang]: $row[belegt]</option>";
}
else {
echo "<option value=$row[stunde]>$row[stunde]</option>";
}
}
}
}
while(mysqli_next_result($conn));
}
也许有人可以帮助我?
答案 0 :(得分:0)
首先将它们存储在单独的数组中,然后按照您的意愿填充。
$query = "SELECT stunde FROM zeiten WHERE buchbar = 2 and
NOT EXISTS (SELECT *
FROM raumbuchung
WHERE zeiten.stunde =
raumbuchung.zeitanfang and belegt = 'belegt');
SELECT zeitanfang, belegt from
raumbuchung where belegt = 'belegt'";
$occupied_arr = array();
$available_arr = array();
if (mysqli_multi_query($conn, $query)) {
do {
if ($result = mysqli_store_result($conn)) {
while ($row = mysqli_fetch_assoc($result)) {
if ($row['belegt']) {
$occupied_arr[] = $row;
}
else {
$available_arr[] = $row;
}
}
}
}
while(mysqli_next_result($conn));
}
echo "Beginn der Veranstaltung: ";
echo "<select name='time' id='t1'>";
foreach ($available_arr as $key => $value) {
echo "<option value=".$value['stunde'].">".$value['stunde']."</option>";
}
foreach ($occupied_arr as $key => $value) {
echo "<option value=".$value['zeitanfang']."disabled>".$value['zeitanfang'].": ".$value['belegt']."</option>";
}
echo "</select>";