CodeIgniter Forums
update_batch() where - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: update_batch() where (/showthread.php?tid=61090)



update_batch() where - El Forum - 09-15-2014

[eluser]ZioN[/eluser]
I've been looking for a solution for my problem for a while now, but I cannot find the right answer. Perhaps because there isn't one, but that's why I am here.

I want to update alot of rows at once, I use update_batch() for this which works. But it lacks something I really need. I need to specify another where.

Case:
I am building a permission system and I want to update all the permissions of a group at once. I have a table with a group id, a permission id and a value. I can update the value based on the permission id, but I want to update the value based on the group id AND permission id.

What would be the best approach to do this?

Controller:
Code:
public function update(){
        $gid = $this->input->post('gid');
        $this->load->model('permission_model');
        if($this->permission_model->update_permission($gid)){
            $this->session->set_flashdata('success', 'Successfully updated permissions.');
            redirect('my_url');
        }
        else{
            $this->session->set_flashdata('errors', 'Something went wrong while updating the permissions.');
            redirect('my_url');
        }
    }
Model:
Code:
public function update_permission($gid){
        $data = array(
                array(
                    'gp_permissionid' => 1,
                    'gp_value' => $this->input->post(''),
                ),

        $query = $this->db->update_batch('table_name', $data, 'gp_permissionid');
        if($this->db->trans_status() === TRUE){
            return true;
        }
        else{
            return true;
        }      
    }