2014-11-22 75 views
0

我似乎無法找到我的代碼出了什麼問題。我希望能夠刪除已在表中檢查過的記錄。Codeigniter ::在複選框中刪除多條記錄

這是我的看法:

 <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功能,這是所謂的觀點:

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!' 
 
     }); 
 
    } 
 
    }); 
 
    
 
    }); 
 
}

我的控制器:

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

 
}

型號:

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

沒有通過螢火蟲返回的錯誤。我不確定有什麼問題,並且我試着根據其他用戶的其他問題修改我的代碼,這些問題在這裏以堆棧的形式回答,但我仍然無法工作。任何幫助深表感謝。我對Codeigniter和PHP相當陌生。提前再次感謝!

+0

請確保所選的ID確實在服務器上發送,請先檢查。 – Ghost 2014-11-22 14:46:07

+0

'<?= base_url()?> category/remove_category/ id?>'and your controller「public function remove_category($ id)」 – avenda 2014-11-23 00:35:44

+0

@Ghost我已經做到了。 – Frenkey 2014-11-23 02:42:43

回答

0

您應該使用一個foreach循環來刪除。在Controller

public function remove_category() 
{ 

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

}