-6ren">
gpt4 book ai didi

php - 如何使用php中的复选框删除记录?

转载 作者:行者123 更新时间:2023-11-30 00:02:49 25 4
gpt4 key购买 nike

需要删除记录,这是我的代码:

<input type="submit" name="delete" value="delete"/>  
<?php
if(isset($_POST['delete']))
{
$cnt=array();
$cnt=count($_POST['chkbox']);
for($i=0;$i<$cnt;$i++)
{
$del_id=$_POST['chkbox'][$i];
$query="DELETE FROM menu_detail WHERE vt_id=".$del_id;
mysql_query($query);
}
}
?>
// I draw checkboxes using this where as I m fetching data from table...
<?php
$col = "row0"; $i = 0; $a=1;
while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
if ($i == 0) { $col = "row0"; $i = 1; } else { $col = ""; $i = 0; }
?>
<tr class="<?php echo $col; ?>">
<td>
<input type="checkbox" name="chkbox" value="checkbox[<?php echo $row['vt_id']?>]" />
</td>

看看图片你就会知道我被困在哪里了

enter image description here

最佳答案

看看

       $tableRow = array("id","name","code"): // assume It must from Database

<form action="your_action.php" method="post" id="bulkDel" >

<table>
<thead>
<th><input type="checkbox" id="checkAll" /></th>
<th>....</th> <!--and so on-->
</thead>
<?php
foreach($tableRow as $row){
?>
<tr>
<td> <input tyep="checkbox" name="check[]" /></td>
<td>.....</td> <!-- and so on -->
</tr>

<?php

}
?>

</table>
<a href="javascript:void(0);"id="bulkDeleteBut" >Delete selected</a>
</form>

// jquery check all checkboxes

$(document).on('click','#checkAll',function(){
$('input[name="check[]"]').prop('checked',$(this).is(":checked"));
});


$(document).on('click','#bulkDeleteBut',function(){
var len = $('input[name="check[]"]')..serializeArray().length;
if(len>0){
$('#bulkDel').submit();
}else{
alert("Check atleast one record");
}
});


// server side php
if(isset($_POST['check'])){
$ar = $_POST['check'];
foreach($ar as $primary_key){
// perform mysql delete query and return back to table page
}
}

关于php - 如何使用php中的复选框删除记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24878888/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com