我试图用复选框删除一些行,我不确定我做错了什么。 观点:
<table class="table table-hover">
<?php echo form_open('site/delete');?>
<?php
foreach ($query as $row){
echo '<tr><td>
<label class="checkbox">
'.form_checkbox('delete[]', $row['link'])."<a href='".$row['link']."'>".$row['title']."</a></td><td>".substr($row['pub_date'], 5, 12).
"</label>
</td></tr>";
} ?>
<?php echo form_submit('submit','Delete');?>
<?php echo form_close();?>
</table>
控制器:
function delete()
{
$url = $this->input->post('delete');
if(isset($url))
{
$this->load->model('membership_model');
$this->membership_model->delete();
$this->main_menu();
}
else
{
redirect('site/main_menu');
}
模型:
function delete()
{
$delete = $this->input->post('delete');
for($i=0;$i<count($delete);$i++) {
$del_link = $delete[$i];
$this->db->where('link',$del_link);
$this->db->delete('feeds');
}
}
当我点击删除没有任何更改。我想从我的数据库中删除带有复选框的行。
答案 0 :(得分:0)
控制器
public function delete()
{
$did= $this->input->post('delete');
if(!empty ($did))
{
foreach ($did as $key => $value)
{
$res=$this->membership_model->delete($value);//pass particular id to delete
$this->main_menu();
}
}
else
{
redirect('site/main_menu');
}
}
型号:
function delete($fid)
{
$this->db->where('link', $fid);
$this->db->delete('feeds');
}