0

I've read similar questions and answers, still no idea, so do not shoot :)

I am trying this:

Array ( [0] => Array ( [id] => 3 [paid_date] => 2013-06-25 20:37:35 [statement_status] => P ) [1] => Array ( [id] => 4 [paid_date] => 2013-06-25 20:37:35 [statement_status] => P ) )

$this->db->update_batch('credit_statement', $data, 'id'); 

and returns:

A Database Error Occurred
You must use the "set" method to update an entry.

and feel that I respected the Codeigniter book:

$data = array(
   array(
      'title' => 'My title' ,
      'name' => 'My Name 2' ,
      'date' => 'My date 2'
   ),
   array(
      'title' => 'Another title' ,
      'name' => 'Another Name 2' ,
      'date' => 'Another date 2'
   )
);

$this->db->update_batch('mytable', $data, 'title'); 

// Produces: 
// UPDATE `mytable` SET `name` = CASE
// WHEN `title` = 'My title' THEN 'My Name 2'
// WHEN `title` = 'Another title' THEN 'Another Name 2'
// ELSE `name` END,
// `date` = CASE 
// WHEN `title` = 'My title' THEN 'My date 2'
// WHEN `title` = 'Another title' THEN 'Another date 2'
// ELSE `date` END
// WHERE `title` IN ('My title','Another title')

What am i doing wrong?

3
  • 1
    Show your actual array definition PHP statement, not just the printed version. Commented Jun 25, 2013 at 20:13
  • 1
    Please post your code Commented Jun 25, 2013 at 20:24
  • thank you guys, it was a misspelling, instead of $data I use $data_r :D Commented Jun 26, 2013 at 9:22

1 Answer 1

3

You haven't set the $data variable when you call it in the update_batch method.

Change this:

Array ( [0] => Array ( [id] => 3 [paid_date] => 2013-06-25 20:37:35 [statement_status] => P ) [1] => Array ( [id] => 4 [paid_date] => 2013-06-25 20:37:35 [statement_status] => P ) )

To this:

$data = Array ( [0] => Array ( [id] => 3 [paid_date] => 2013-06-25 20:37:35 [statement_status] => P ) [1] => Array ( [id] => 4 [paid_date] => 2013-06-25 20:37:35 [statement_status] => P ) );
Sign up to request clarification or add additional context in comments.

3 Comments

please check your array with var_dump or print_r
sorry, is set in the original code, that was just he array print... with print_r, sure
in fact is was an misspelling of the name of the array, so you showed me the error in an indirect way. you have my vote.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.