删除复选框中的所选数据 [英] Delete selected data in a checkbox
本文介绍了删除复选框中的所选数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在做一个网站,其中我有一组数据与复选框。当我选择多个复选框时,我需要从数据库中删除多个行。我不知道如何传递所选复选框的id到下一页。请帮助我。
I'm making a website on which I have a set of data with checkbox. I need to delete multiple rows from database when I select multiple checkboxes. I don't know how to pass the id of the selected checkboxes to next page. Please help me.
这是我的代码:
$select_qry="select * from data";
$result=mysql_query($select_qry);
$rows=mysql_num_rows($result);
if($rows>0)
{
?>
<form action="delete_submit.php" method="post">
<?php
for($i=0;$i<$rows;$i++)
{
$arr=mysql_fetch_assoc($result);
$id=$arr['id'];
$name=$arr['name'];
//echo $id;echo "<br>";echo $name;
?>
<input name="checkbox[]" type="checkbox" value="<?php echo $id;?>">
<?php
}
}
?>
我将选中的复选框的ID传递到下一页?请帮助我。
How can I pass the selected checkboxes' id to the next page? Please help me.
谢谢
推荐答案
那么 $ _ POST ['checkbox']
将被设置并包含所选ids的数组。
when form will be submitted then $_POST['checkbox']
will be set and contain the array of selected ids.
if(isset($_POST['checkbox']) && count($_POST['checkbox']) > 0){
$deleteIds = $_POST['checkbox']; // it will be an array
$sql = "DEFRE FROM tablename WHERE id in (".implode("," , $deleteIds).") ";
// run the query
}
这篇关于删除复选框中的所选数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文