是否可以使用复选框更改多行值? [英] If it possible to changed multiple rows value using checkbox?

查看:43
本文介绍了是否可以使用复选框更改多行值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我选中复选框时是否可以在数据库中编辑我的状态字段?

If it possible to edit my status field in my database when I check the checkbox?

我想要的是,当我检查表中的多行时,它会在提交后自动将数据库中row ['status']的值更新为yes.

What I want is, when I check multiple rows in my table it updates automatically the value of row['status'] in the database into yes after I submit.

就这样

表格APP

counter | status

100001  | 
100002  | 
100003  |   
100004  | 

当我检查100001和100002时,状态值更改为yes.

And when I checked the 100001 and 100002 the value of status changed to yes.

counter | status

100001  | yes
100002  | yes
100003  |   
100004  | 

下面是我的短代码.

<form name="form1" method="post" action="">
<?php
$mysqli = new mysqli("localhost", "root", "", "app");
$result1 = $mysqli->query("SELECT * FROM APP");
echo'<table id="tfhover">
<tr>
<th>status</th>
<th></th>
</tr>';
while($row = $result1->fetch_assoc()){
echo
'<tr>
<td>'.$row['status'].'</td>
<td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="'.$row['counter'].'"></td>
</tr></table>';
?>
<input id='edit' type='submit' class='button' name='edit' value='Edit'/> 
</form>

<?
if(isset($_POST['edit'])) 
{

}
?>

是否可以这样做?帮助吗?

If it is possible to do this? Help ?

推荐答案

也许您可以尝试以下代码 在php

may be you can try this code at php

<?
if(isset($_POST['edit'])) 
{
     if(is_array($_POST['checkbox'])){
         $status = "yes";
         foreach($_POST['checkbox'] as $key=>$value){
             $stmt = $mysqli->prepare("UPDATE APP SET status=? WHERE counter= ?");
             $stmt->bind_param('ss', $status, $value);
             $stmt->execute();             
         }
     }else{
         echo "No changes";
     }
}
?>

这篇关于是否可以使用复选框更改多行值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆