How can i give a where condition before update_batch in codeigniter? -


i want update table input same input fields names array , has add more function generates input fields this:

i want update_batch in codeigniter model created function this: code block:

    function update_batch_all($tblname,$data=array(),$userid)     {        $this->db->trans_start();        $this->db->where('userid',$userid);        $this->db->update_batch($tblname,$data);        $this->db->trans_complete();        return true;     } 

it not working. can 1 me how can update tables data update batch has condition?

you can read docs update_batch() here

here's short summary:

you pass in associative array has both, key, , update value. third parameter update_batch() call, specify key in assoc array should used clause.

for example:

$data = array(   array(     'user_id' => 1,     'name' => 'foo'   ), array(     'user_id' => 2,     'name' => 'bar'   ) );  $this->db->update_batch($tbl, $data, 'user_id'); 

breakdown of arguments passed:$tbl table name. $data associative array. 'user_id' tells ci user_id key in $data clause.

effect of above query: name user user_id = 1 gets set foo , name user user_id=2 gets set bar.

in case, if want set same user_id key in each array data array, can quick loop:

foreach ($data &$d) {    $d['user_id'] = $user_id; }   $this->db->update_batch($tbl, $data, 'user_id'); 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -