我正在尝试在php中制作出勤图表。 我希望通过单击单选按钮增加数据库中的出勤计数器。 我如何检索值,然后为每个“是”增加?
我需要将更新代码放在下一页吗?
我试着这样..但是这些字段没有得到更新..
if($class=="cse")
{
$result = mysqli_query($con, "SELECT * FROM cse");
echo "<table border=15px cellspacing=40>";
echo "<tr><th>NAME</th><th>BUPIN</th><th>ATTENDANCE</th></tr>";
while ($row = mysqli_fetch_array($result))
{
echo "<tr><td>" . $row["name"] . "</td>" . "<td>" . $row["bupin"] . "</td>";
echo "<td>" . "<input type='radio' name='presence[".$row["bupin"]."]' value='yes'>Yes";
echo "<input type='radio' name='presence[".$row["bupin"]."]' value='no'>No" . "</td></tr>";
}
echo "</table>";
?>
<html>
<form action= "final6.php" method="POST">
<input type="Submit" value="Submit">
</form>
</html>
}}
,下一页代码为:if (isset($_POST["presence"]))
{
foreach ($presence as $key => $val)
{
if ($val == 'yes')
{
$sql = "UPDATE cse SET 1attendance = 1attendance + 1 WHERE bupin = " .$key;
msyqli_query($con, $sql);
}
}
}
echo "Attendance marked successfully..";
}
答案 0 :(得分:0)
如果bupin是表cse
中的主键(id),那么试试这个。当然,请将查询中的field
更改为您要填写的内容。
$result = mysqli_query($con, "SELECT * FROM cse");
echo "<table border=15px cellspacing=40>";
echo "<tr><th>NAME</th><th>BUPIN</th><th>ATTENDANCE</th></tr>";
while ($row = mysqli_fetch_array($result)) {
echo "<tr><td>" . $row["name"] . "</td>" . "<td>" . $row["bupin"] . "</td>";
echo "<td>" . "<input type='radio' name='presence[".$row["bupin"]."]' value='yes'>Yes";
echo "<input type='radio' name='presence[".$row["bupin"]."]' value='no'>No" . "</td></tr>";
}
echo "</table>";
if (isset($_POST["presence"])) {
foreach ($presence as $key => $val) {
if ($val == 'yes') {
$sql = "UPDATE cse SET field = field + 1 WHERE bupin = " . $key;
msyqli_query($con, $sql);
}
}
}