this is my fetched table and i have added check box to every row now i want to update this table if specific field is checked so kindly suggest me something`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++;
Here is fetched data and the check box.
your design need to be changed, do something like
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 is your solution. Take a look at this page
You can implement it like in here
$(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')); }); });
Since, Database Table structure is not provided. I am assuming : Primary Key & Auto-Increment column name as user_id
. (Change it, if you having other column name).
<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>
approve.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.
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.