2014-10-03 91 views
0

我有我的代碼中的問題,我想通過刪除按鈕笨刪除從我的數據庫中的一些數據..這是我的觀點:笨:刪除數據

<a href="<?php echo site_url('admin/m_pakar/delete');?>/<?php echo 
$result['pakar_id'];?>"<i class="fa fa-trash-o fa-fw"></i></a> 

此代碼在我的控制器:

public function delete() { 

    $datasend = array(
      'class'=>'', 
      'message'=>'', 
     ); 

    $id = $this->input->post("id", TRUE); 
    $this->general->set_table('data_pakar'); 
    $this->general->where(array('pakar_id' => $id)); 

    $deletepakar = $this->general->delete(); 
    if ($deletepakar) {   
     $datasend = array(
        'class'=>'class="alert alert-success alert-dismissable"', 
        'message'=>'<button type="button" class="close" data-dismiss="alert" 
        aria-hidden="true">&times;</button>Data berhasil dihapus.', 
     ); 
    } else { 

     $datasend = array(
        'class'=>'class="alert alert-danger alert-dismissable"', 
        'message'=>'<button type="button" class="close" data-dismiss="alert" 
        aria-hidden="true">&times;</button>Data gagal dihapus.', 
     ); 
    } 

    $datasend['pakar'] = $this->general->get_result_array(); 
    $datasend['level'] = $this->general->get_result_array(); 

    $dataview['content'] = $this->load->view('admin/m_pakar/index', $datasend, TRUE); 
    $this->load->view($this->template, $dataview); 

} 

這我的模型:

public function delete() { 

    $delete = $this->db->delete($this->tbname); 
    return $delete; 
} 

有了這個代碼,$deletepakar = $this->general->delete();不行。並且出來的聲明是Data gagal dihapus ...我的代碼有什麼問題?

+0

最近,我在這裏找到答案可能是有幫助: - http:// stack overflow.com/questions/26173994/deleting-a-specific-row-using-codeigniter/ – 2014-10-03 08:46:25

回答

0

希望它必須是一個GET

$id = $this->input->get("id", TRUE); 
0

嘗試

<a href="<?php echo site_url('admin/m_pakar/delete/'.$result['pakar_id']);?>"><i class="fa fa-trash-o fa-fw"></i></a> 

控制器: -

public function delete($id) { 
$this->general->where(array('pakar_id' => $id)); // will get you directly from url 

更多: - Deleting a specific row using codeigniter