$statement = $db->prepare("
SELECT A.Vorname
, A.Nachname
, O.IndexcardRight
, O.QuizRight
, O.Admin_AdminID
FROM Admin A
LEFT
JOIN AdminOfModule O
ON O.Admin_AdminID = A.AdminID
WHERE O.AdminTyp = 'Student'
GROUP
BY A.AdminID
");
$statement->execute();
$admin = $statement->fetchAll(PDO::FETCH_ASSOC);
$count = $statement->rowCount();
这是带有更新 SQL 的 PHP 和 HTML 代码,它确实有效,因为我没有唯一的 id
我尝试了一些东西,比如给名字或 id quiz[],但我不能在 php 函数中调用它。并且找不到太多的方法来做到这一点。
<form method="post">
<?php
$i = 2;
$y = 2;
foreach ($admin as $row) {
$aii = $row['Admin_AdminID'];
$i++;
$y++;
echo '<label>' . $row["Vorname"] . $row["Nachname"] . '</label>';
echo '<br>';
echo '<label> Quiz</label>';
//echo'<input type="hidden>"';
echo '<input type="checkbox" name="quiz' . $i . '" id="quiz' . $i . '"> ';
echo '';
echo '<label> Indexcard</label>';
echo '<input type="checkbox" name="indexcard' . $i . '" id="indexcard' . $i . '">';
echo '<br>';
//quizx indexcardx wenn button geklickt und wenn quizx isset dann update table adminofmodule set quizright =1 where
}
if (isset($_POST['submit'])) {
//$ic = $_POST["indexcard$i"];
//$q = $_POST["quiz$i"];
if (isset($_POST["quiz$i"])) {
$stmt = $db->prepare("UPDATE AdminOfModule SET QuizRight = 1 WHERE '$aii' = '$i' ");
$stmt->execute();
}
else {
$stmt1 = $db->prepare("UPDATE AdminOfModule SET QuizRight = 0 WHERE '$aii' = '$i' ");
$stmt1->execute();
}
if (isset($_POST["indexcard$i"])) {
$stmt2 = $db->prepare("UPDATE AdminOfModule SET IndexcardRight = 1 WHERE'$aii' = '$i'");
$stmt2->execute();
}
else {
$stmt3 = $db->prepare("UPDATE AdminOfModule SET IndexcardRight = 0 WHERE'$aii' = '$i' ");
$stmt3->execute();
}
}
echo '<input type="submit" name="submit" id="submit">';
?>
</form>
问题是,如果我选中第一行的复选框,它将为 0,但如果单击最后一个复选框,它将全部设置为 1。