我在 HTML 表格中使用复选框,我想做的是使用批量操作。就像有人选中两个或三个复选框并使用批量删除操作一样,因此应该删除表中所有选中的项目。
这是我的 HTML 代码
<table id="datatable_example" class="responsive table table-striped table-bordered" style="width:100%;margin-bottom:0; ">
<thead>
<tr>
<th style="width:0px; padding-right:0px;" class="no_sort"> <label class="checkbox ">
<input type="checkbox">
</label>
</th>
<th style="width:200px;" class="no_sort"> Institue </th>
<th style="width:150px;" class="no_sort"> Education </th>
<th style="width:300px;" class="no_sort"> Description </th>
<th style="width:150px;" class="ue no_sort"> Started </th>
<th style="width:150px;" class="ue no_sort"> Completion </th>
<th class="ms no_sort "> Actions </th>
</tr>
</thead>
<tbody>
<?php echo $educations ?>
</tbody>
</table>
编辑:这是表格的正文部分。因为我在 PHP 中工作,所以我做了这样的事情。
$educations .= "<tr>
<td><label class=\"checkbox\">
<input type=\"checkbox\">
</label></td>
<td class=\"to_hide_phone\"> $institue_name</td>
<td class=\"to_hide_phone\"> $education_name</td>
<td>$education_desc</td>
<td>$education_started</td>
<td>$education_ended</td>
<td class=\"ms\">
<div class=\"btn-group1\">
<a href=\"education-edit.php?id=$education_id\" class=\"btn btn-small\" rel=\"tooltip\" data-placement=\"left\" data-original-title=\" edit \">
<i class=\"gicon-edit\"></i></a>
<a class=\"btn btn-small\" rel=\"tooltip\" data-placement=\"top\" data-original-title=\"View\">
<i class=\"gicon-eye-open\"></i>
</a>
<a class=\"btn btn-small\" rel=\"tooltip\" data-placement=\"bottom\" data-original-title=\"Remove\"><i class=\"gicon-remove \"></i></a>
</div>
</td>
</tr>";
如果我选择/检查两行并单击删除操作,那么我想这样做,那么这两行都应该被删除。我想知道如何执行此操作。
抱歉,如果我不清楚,我正在尝试但无法弄清楚如何实现它。
更新:这是我迄今为止在您的帮助下所做的尝试。
HTML 区域:
<form action="<?php $_PHP_SELF ?>" method="post">
<div class="content top">
<table id="datatable_example" class="responsive table table-striped table-bordered" style="width:100%;margin-bottom:0; ">
<thead>
<tr>
<th style="width:0px; padding-right:0px;" class="no_sort"> <label class="checkbox ">
<input type="checkbox" class="chk_boxes">
</label>
</th>
<th style="width:200px;" class="no_sort"> Institue </th>
<th style="width:150px;" class="no_sort"> Education </th>
<th style="width:300px;" class="no_sort"> Description </th>
<th style="width:150px;" class="ue no_sort"> Started </th>
<th style="width:150px;" class="ue no_sort"> Completion </th>
<th class="ms no_sort "> Actions </th>
</tr>
</thead>
<tbody>
<?php echo $educations ?>
</tbody>
</table>
<div class="row-fluid control-group">
<div class="pull-left span6 " action="#">
<div>
<div class="controls inline input-large pull-left">
<select name="bulkaction" data-placeholder="Bulk actions: " class="chzn-select " id="default-select">
<option value=""></option>
<option value="delete">Delete</option>
</select>
</div>
<button type="submit" name="submitbulkaction" class="btn btn-inverse inline">Apply</button></form>
内部tbody区域:
$educations .= "<tr>
<td><label class=\"checkbox\">
<input type=\"checkbox\" class=\"chk_boxes1\" name=\"ids[]\" value=\"$education_id\">
</label></td>
<td class=\"to_hide_phone\"> $institue_name</td>
<td class=\"to_hide_phone\"> $education_name</td>
<td>$education_desc</td>
<td>$education_started</td>
<td>$education_ended</td>
<td class=\"ms\">
<div class=\"btn-group1\">
<a href=\"education-edit.php?id=$education_id\" class=\"btn btn-small\" rel=\"tooltip\" data-placement=\"left\" data-original-title=\" edit \">
<i class=\"gicon-edit\"></i></a>
<a class=\"btn btn-small\" rel=\"tooltip\" data-placement=\"top\" data-original-title=\"View\">
<i class=\"gicon-eye-open\"></i>
</a>
<a class=\"btn btn-small\" rel=\"tooltip\" data-placement=\"bottom\" data-original-title=\"Remove\"><i class=\"gicon-remove \"></i></a>
</div>
</td>
</tr>";
当我按下应用按钮时执行的部分:
if(isset($_POST['submitbulkaction']))
{
$ids = array();
foreach ((array) $_POST['ids'] as $id) {
// sanitize input
$id = (int) $id;
if ($id) $ids[] = $id;
}
// good idea to say how much row will be deleted to DB
$limit = count($ids);
if ($limit) {
// can see the output
$ids = join(',', $ids);
mysql_query("DELETE * FROM cv_education WHERE id IN ($ids) LIMIT $limit");
}
}
好吧,现在我没有收到任何错误,而且数据也没有从数据库表中删除。
我的表名是:
cv_education
任何想法我做错了什么?