• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
update_batch() where

#1
[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;
        }      
    }


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.