[英]if checkbox is checked in html table then i want to update the value of that row when update button is pressed
这是我提取的表格,我已经为每一行添加了复选框,现在我想更新此表格,如果特定字段被选中,请建议我一些东西`while($record=mysql_fetch_array($res)){
echo "<tr align='center'>";
echo "<td>".$record['YourName']."</td>";
echo "<td>".$record['FatherName']."</td>";
echo "<td>".$record['RegNum']."</td>";
echo "<td>".$record['Gender']."</td>";
echo "<td name='$i' >".$record['MobileNumber']."</td>";
echo "<td>".$record['Password']."</td>";
echo "<td>".$record['specialist']."</td>";
echo "<td>".$record['area']."</td>";
echo "<td>".$record['building']."</td>";
echo "<td>".$record['room']."</td>";
echo "<td><input type='checkbox' name='$i' value='Bike' align='center'></td>";
echo "</tr>";
$i++;
这是获取的数据和复选框。
你的设计需要改变,做类似的事情
echo "<tr align='center'>";
echo "<td>".$record['YourName']."</td>";
echo "<td>".$record['FatherName']."</td>";
echo "<td>".$record['RegNum']."</td>";
echo "<td>".$record['Gender']."</td>";
echo "<td name='$i' >".$record['MobileNumber']."</td>";
echo "<td>".$record['Password']."</td>";
echo "<td>".$record['specialist']."</td>";
echo "<td>".$record['area']."</td>";
echo "<td>".$record['building']."</td>";
echo "<td>".$record['room']."</td>";
echo "<td><a href='edit.php?id={you id for record}'>Edit</a></td>";
echo "</tr>";
jQuery 是您的解决方案。 看看这个页面
你可以像在这里一样实现它
$(document).ready(function() { //set initial state. $('#textbox1').val($(this).is(':checked')); $('#checkbox1').change(function() { if($(this).is(":checked")) { var returnVal = confirm("Are you sure?"); $(this).attr("checked", returnVal); } $('#textbox1').val($(this).is(':checked')); }); });
因为,没有提供数据库表结构。 我假设:主键和自动递增列名称为user_id
。 (更改它,如果您有其他列名)。
<form method='POST' action='approve.php'>
<table>
<?
$i=1;
while($record=mysql_fetch_array($res)){
echo "<tr align='center'>";
echo "<td>".$record['YourName']."</td>";
echo "<td>".$record['FatherName']."</td>";
echo "<td>".$record['RegNum']."</td>";
echo "<td>".$record['Gender']."</td>";
echo "<td name='$i' >".$record['MobileNumber']."</td>";
echo "<td>".$record['Password']."</td>";
echo "<td>".$record['specialist']."</td>";
echo "<td>".$record['area']."</td>";
echo "<td>".$record['building']."</td>";
echo "<td>".$record['room']."</td>";
// Pay Attention Here in this checkbox.
echo "<td><input type='checkbox' name='Approve[]' value='".$record['user_id']."' align='center'></td>";
echo "</tr>";
$i++;
}?>
</table>
</form>
批准.php
<?php
$countApprovedCheckbox = sizeof($_POST['Approve']);
for($i=0;$i<$countApprovedCheckbox;$i++) {
$userID = $Approve[$i];
$query = "UPDATE TableName SET ApproveColumnName='Approve' WHERE user_id='$userID'";
//Execute Your Query Here.
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.