Codeigniter从数据库问题中删除

时间:2014-05-08 13:48:17

标签: php forms function codeigniter

我是codeigniter的新手,我已经设法让插入工作进入数据库并且我已经完成了从数据库中删除的代码,但是当点击作业删除它时,它只是刷新并且作业仍然在数据库中。

我的控制器

public function deleteclientform(){
    $this->load->helper('form');
    $this->load->model("clientmodel"); 
    $data['clients']=$this->clientmodel->getallclients();
    $data['title']="Delete Job";
    $this->load->view("deleteclientform",$data); 
}

public function delete(){
    $films=$this->input->post('clients');
    $this->load->model("clientmodel");
    foreach($clients as $jobno)
    {
        $this->clientmodel->deleteclient($jobno);
    }
     redirect('/nav/home', 'refresh');
}

我的模特

function deleteclient($jobno)

{
$this->db->where('jobno', $jobno);
$result=$this->db->delete('client');
return $result;
}

我的观点

echo form_open('client/delete');

foreach($clients as $client)
{
echo "<p>";
echo form_label($client->job, 'client'.$client->jobno);
$data = array('name' => 'clients[]', 'jobno'=>'client'.$client->jobno, 'value' =>    $client->jobno);
echo form_checkbox($data);
echo "</p>";
}
echo form_submit("delete_btn","Delete these Jobs");
echo form_close();

1 个答案:

答案 0 :(得分:1)

public function delete(){
    $films=$this->input->post('clients');
    $this->load->model("clientmodel");
    foreach($films as $jobno)
              ^ this
    {
        $this->clientmodel->deleteclient($jobno);
    }
     redirect('/nav/home', 'refresh');
}

控制器中的此功能错误。

当你想要$clients时,你指的是$films