Php 如何使用选项标记更新sql中的多行
我需要用一次提交来更新mysql表中的多行,而老师可以给每个学生评分并一次保存所有行 有人能用正确的方法帮忙吗 此代码仅记录最后一行Php 如何使用选项标记更新sql中的多行,php,mysql,sql,Php,Mysql,Sql,我需要用一次提交来更新mysql表中的多行,而老师可以给每个学生评分并一次保存所有行 有人能用正确的方法帮忙吗 此代码仅记录最后一行 <form class="multisteps-form__form clearfix" action="?do=Update" method="post" id="wizard"> <div class="m
<form class="multisteps-form__form clearfix" action="?do=Update" method="post" id="wizard">
<div class="multisteps-form__panel js-active" data-animation="slideVert">
<?php
$stmt = $con->prepare("SELECT * FROM student ");
$stmt->execute();
$rows = $stmt->fetchAll();
foreach($rows as $row) {
$id = $row['id'];
$math_activity = $row['math_activity'];
$math_attendance = $row['math_attendance'];
$math_evaluation = $row['math_evaluation'];
?>
<input type="hidden" name="id[]" value="<?php echo $id ?>" />
<div class="row">
<div class="col-md-2">
<div class="badge-selection">
<h3><?php echo $row['student_name']; ?></h3></div></div>
<div class="col-md-3">
<div class="n-select-option">
<select name="math_activity">
<option>Activity</option>
<option name="2" value="25">25</option>
<option name="3" value="50">50</option>
</select></div></div>
<div class="col-md-3">
<div class="n-select-option">
<select name="math_attendance">
<option>Attendance</option>
<option name="2" value="25">25</option>
<option name="3" value="50">50</option>
</select></div></div>
<div class="col-md-3">
<div class="n-select-option">
<select name="math_evaluation">
<option>Evaluation</option>
<option name="2" value="25">25</option>
<option name="3" value="50">50</option>
</select></div></div></div>
<?php } ?>
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" value="Save" class="btn btn-primary btn-lg" />
</div></div></div></div></div></div></form>
<?php
$count=count(array($_POST["id"]));
for($i=0;$i<$count;$i++){
$do = isset($_GET['do']) ? $_GET['do'] : 'Manage';
if ($do == 'Update'){
$id = $_POST['id'];
$math_activity = $_POST['math_activity'];
$math_attendance = $_POST['math_attendance'];
$math_evaluation = $_POST['math_evaluation'];
$stmt = $con->prepare("UPDATE student SET math_activity[$i] = ?, math_attendance[$i] = ?, math_evaluation[$i] = ? WHERE id[$i] = ?");
$stmt->execute(array($math_evaluation, $math_attendance, $math_activity, $id));
}}?>
活动
25
50
出勤
25
50
评价
25
50
我想,您的表头是固定的,不应该更改吗
表学生:
math_activity | math_attendance | math_evaluation <- tableHead
1 6436 3445
2 345 335 <-inserted rows
$stmt = $conn->prepare("UPDATE student SET math_activity = ?, math_attendance = ?, math_evaluation = ? WHERE id = ?")
foreach($rows as $row => $value){
$stmt->bind_param("iiii", $math_activity[$row], $math_attendance[$row], $math_evaluation[$row], $id[$row]); //watch ou Datatypes ("iiii" are correct)
$stmt->execute();
}
math_活动| math_出勤| math_评估$value){
$stmt->bind_param(“iiii”、$math_activity[$row]、$math_attention[$row]、$math_evaluation[$row]、$id[$row]);//监视ou数据类型(“iiii”正确)
$stmt->execute();
}
我想,您的表头是固定的,不应该更改吗
表学生:
math_activity | math_attendance | math_evaluation <- tableHead
1 6436 3445
2 345 335 <-inserted rows
$stmt = $conn->prepare("UPDATE student SET math_activity = ?, math_attendance = ?, math_evaluation = ? WHERE id = ?")
foreach($rows as $row => $value){
$stmt->bind_param("iiii", $math_activity[$row], $math_attendance[$row], $math_evaluation[$row], $id[$row]); //watch ou Datatypes ("iiii" are correct)
$stmt->execute();
}
math_活动| math_出勤| math_评估$value){
$stmt->bind_param(“iiii”、$math_activity[$row]、$math_attention[$row]、$math_evaluation[$row]、$id[$row]);//监视ou数据类型(“iiii”正确)
$stmt->execute();
}
名为student的表中名为math_activity的列高度指示模式设计不佳。名为student的表中名为math_activity的列高度指示模式设计不佳