Ghugu Ghugu - 2 months ago 11
PHP Question

how to do on uncheck checkbox doesnot delete all

hello my function doesnot delete all one checkbox remains checked as i uncheked it but there is no effect on that i need help

here is my controller code

public function create_evaluation(){
$users = $this->data['users'] = $this->user_model->get_all(array('user_id!='=>1,'active=' => 1));
/*display selected users */
$q = 'select group_concat(distinct user_id) as users from section_permissions where section_id = 0 ';
$row = $this->section_permission_model->q_single($q);
$team_leader = $this->data['team_leader'] = ($row['users']) ? explode(',', $row['users']) : array();

if ($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,
);
$this->section_permission_model->insert($data);
}
$this->session->set_flashdata('success','Permissions updated successfully');
redirect('admin/Evaluation/create_evaluation');
}
}

}


view code

<?php echo form_open("");?>
<?php foreach($users as $user){ ?>
<ul class="name">
<li><span class="users_check">

<input type="checkbox" name="assigned_ids[]" <?=(in_array($user['user_id'],$team_leader))?'checked':''?> class="other" value="<?=$user['user_id']?>" ></span><p><?= $user['f_name']?> </p></li>
</ul>
<? } ?>

<button id ="submit" class="btn btn-default">CREATE</button>
<?php echo form_close();?>


here m using checkbox value it works fine but it doesnot delete all at the end one checkbox remains as checked i want to delete all if i uncheck all
please help

Answer

May be the problem is on your sql query

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

Your delete query syntax may be wrong.