我有一个php文件,它将mysql db中的记录显示到html表中。对于每一行,我都添加了一个复选框。我想为给定行选中一个复选框,并仅为该行更新字段。我知道必须创建一个UPDATE语句然后在更新UPDATE将处理的SUBMIT上。我已经研究过,但不知道下一步该做什么。
这就是我所拥有的
$sql = "SELECT * , date_format(created_at, '%m/%d/%y'), time_format(created_at, '%h:%i:%s') FROM `report_facility_maintenance` LEFT JOIN facilities ON report_facility_maintenance.facility_id = facilities.id ORDER BY created_at DESC";
$result = $conn->query($sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
// while($row = $result->fetch_assoc()) {
echo "<table border=1, width=900px; >
<tr>
<th width=300px>Request Information</th>
<th>Details</th>
<th>Complete</th>
</tr>";
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td align=Left> <br> <strong>Location: </strong>" . $row["name"].
" <br> <strong>Type: </strong>" . $row["maint_type"].
" <br> <strong>Date: </strong>" . $row["date_format(created_at, '%m/%d/%y')"].
" <br> <strong>Time: </strong>" . $row["time_format(created_at, '%h:%i:%s')"].
"<br><strong>Submitted By: </strong>". $row["submitted_by"].
"<br><br></td><td>".$row["details"]. "</td><td><input type=checkbox name=completed[] value=complete /></td>";
echo "</tr>";
//print_r($row);
// echo $result;
}
echo "</table><br />";
} else {
//echo "0 results";
}
echo "<input type=submit name=completedSubmit value= Clear Selected />";
$conn->close();
?>
答案 0 :(得分:0)
谢谢Marc B.这帮助我开始了。我设法通过了 $ id = $ _POST ['completed']到if(isset())语句并根据需要执行我的sql查询以根据需要更新数据库。