$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();
Here is the PHP and HTML Code with the Update SQL which doenst work for sure because i have no unique id's
i tried some stuff like give in the name or id quiz[] but i cannot call it in the php function. And couldnt find much ways to do it.
<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>
The Problem is, if i check the Checkbox at the first rows it will stand 0 but if click the last Checkbox it sets all to 1.