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

时间:2016-04-28 18:23:00

标签: php html css html5

这是我提取的表格,我已经为每一行添加了复选框,现在我想更新此表格,如果检查了特定字段,那么请建议我一些事情($ record = mysql_fetch_array($ res)){

{{1}}

这是获取的数据和复选框。

Picutre

3 个答案:

答案 0 :(得分:2)

您的设计需要更改,请执行类似

的操作
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>";
它看起来会像 enter image description here

答案 1 :(得分:0)

jQuery是您的解决方案。看看this page

您可以像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'));        
}); });

答案 2 :(得分:0)

由于未提供数据库表结构。我假设:主键&amp; 自动增量列名称为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>

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

}
?>