Codeigniter ::删除复选框中的多个记录 [英] Codeigniter:: deleting multiple records in checkbox

查看:120
本文介绍了Codeigniter ::删除复选框中的多个记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎找不到我的代码有什么问题。我想要能够删除已在表中检查的记录。

I can't seem to find what is wrong with my code. I want to be able to delete records which have been checked in a table.

这是我的VIEW:

       <table id="table" name="table" class="table table-bordered table-condensed table-striped table-primary table-vertical-center checkboxs">
              <thead>
                <tr>
                  <th style="width: 1%;" class="uniformjs"><input type="checkbox" /></th>
                  <th class="center">Item Category</th>
                  <th class="center" style="width: 90px;">Actions</th>
                </tr>
              </thead>
              <?php foreach($categorycontent->result() as $row): ?>
                <tr>
                  <th style="width: 1%;" class="uniformjs"><input type="checkbox" name="delete[]" value="<?php echo $row->id; ?>"/></th>
                  <td class="center"><?php echo $row->category_name; ?></td>
                  <td class="center">
                    <a href="#" class="btn-action glyphicons pencil btn-success" title="Edit" onClick="popedit('<?php echo $row->id; ?>', '<?php echo base_url(); ?>category/update_category/', 'category')"><i></i></a>
                    </td>
                </tr>
              <?php endforeach; ?>
            </table>

<script type="text/javascript">
  $(function()
  {

    popadd("#newcategory", "<?php echo base_url(); ?>category/create_category/", 'category');
    popdeletechecked("#deletecategory", "Deleting this record/s will delete all linked information.</br>Are you sure you want to delete it?",  "<?php echo base_url(); ?>category/remove_category/");
  });
</script>

我在视图中调用的ajax函数:

My ajax function which was called in the view:

function popdeletechecked(buttonid, msg, url)
{
  $(buttonid).click(function(){
    
    bootbox.confirm(msg,'No', 'Yes', function(result) {

      if(result) {
        $.ajax({
          url     : url,
          type    : 'POST',
          success : function(){
            window.location = url;
          }
        });
      }
      else {
      $.gritter.add({// Doesn't work on page reload
        title: 'Deleting Cancelled!'
      });
    }
  });
    
  });
}

我的控制器:

My Controller:

public function remove_category()
{
    
    $checked = $this->input->post('delete');
    $this->category_model->delete_category($checked);
  
    redirect('category/read_category');

}

b $ b

function delete_category($id)
{
  $this->db->where('id', $id);
  $this->db->delete('tblitemcategories');
}

没有firebug返回的错误。我不知道是什么问题,我已经尝试改变我的代码,基于其他用户的其他问题,这是在堆栈中回答,但我仍然不工作。任何帮助是非常赞赏。我对Codeigniter和PHP很新。再次提前感谢!

There are no errors returned by firebug. I'm not sure what's wrong and I've tried changing my code based on the other questions of other users which were answered here in stack, but mine still doesn't work. Any help is much appreciated. I'm pretty new to Codeigniter and PHP. Thanks again in advance!

推荐答案

您应该使用 foreach 删除。在控制器中:

You should use a foreach loop to delete. In the Controller:

public function remove_category()
{

    $checked = $this->input->post('delete');
    foreach($checked as $val){
        $this->category_model->delete_category($val);
    }
    redirect('category/read_category');

}

这篇关于Codeigniter ::删除复选框中的多个记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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