[英]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.