简体   繁体   English

如果在 html 表中选中复选框,那么我想在按下更新按钮时更新该行的值

[英]if checkbox is checked in html table then i want to update the value of that row when update button is pressed

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)){这是我提取的表格,我已经为每一行添加了复选框,现在我想更新此表格,如果特定字段被选中,请建议我一些东西`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>";

it will look like它看起来像在此处输入图片说明

jQuery is your solution. jQuery 是您的解决方案。 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 .我假设:主键自动递增列名称为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

<?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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM