[英]how to do on uncheck checkbox doesnot delete all
你好,我的功能不會刪除所有一個復選框,因為我取消選中它后仍保持選中狀態,但是對我沒有任何幫助
這是我的代碼
if(array_key_exists('assigned_ids',$this->input->post())){
$select_assigned_ids = $this->input->post('assigned_ids[]');
/* delete previous entries for user_id */
$q = 'Delete from section_permissions where user_id != 1 and section_id = 0 ';
$this->section_permission_model->qwr($q);
if ($this->form_validation->run() == FALSE) {
foreach($select_assigned_ids as $tlusers){
$data = array(
'user_id' => $tlusers,
);
$test = $this->section_permission_model->insert($data);
//echo"<pre>";print_r($test);die;
}
$this->session->set_flashdata('success','Permissions updated successfully');
redirect('admin/Evaluation/create_evaluation');
}
}else{
/* delete previous entries for user_id */
$q = 'Delete from section_permissions where user_id != 1 and section_id = 0 ';
$this->section_permission_model->qwr($q);
}
它可以按我的要求很好地工作,但是它也不會插入和刪除任何記錄,但是使用flashdata可以按我的要求工作
我猜,您知道,如果您uncheck all
復選框並提交表單,那么您將不會獲得控制器或模型中復選框的值。 請參見下面的示例:
正確的方法
您需要檢查是否選中了復選框...在控制器中執行此操作。
if(array_key_exists('assigned_ids',$this->input->post())){
//First of all delete previous entries for user_id
//Insert new records for user_id (value = new checkbox values)
}else{
//Checkbox is unchecked....
//delete all previous entries for user_id
}
希望對您有幫助。
可能是您的sql查詢出現問題
if ($this->input->post()) {
$select_assigned_ids = $this->input->post('assigned_ids[]');
/* delete previous entries for user_id */
$q = 'Delete from section_permissions where section_id = 0 ';
$this->section_permission_model->qwr($q);
if ($this->form_validation->run() == FALSE) {
foreach($select_assigned_ids as $tlusers){
$data = array(
'user_id' => $tlusers,
);
$this->section_permission_model->insert($data);
}
}
}
您的刪除查詢語法可能是錯誤的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.