Welcome Guest, Not a member yet? Register   Sign In
Problem with update_batch()
#9

[eluser]danmontgomery[/eluser]
Instead of wondering, you could look at the source to see what it's doing, and see that is does, in fact, form a case statement in support of separate where clauses for each update.

https://bitbucket.org/ellislab/codeignit...infomation

Quote:$this->db->update_batch();

Generates an update string based on the data you supply, and runs the query. You can either pass an
array or an object to the function. Here is an example using an array:

Code:
$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')

The first parameter will contain the table name, the second is an associative array of values, the third parameter is the where key.


Messages In This Thread
Problem with update_batch() - by El Forum - 05-04-2011, 04:27 PM
Problem with update_batch() - by El Forum - 05-05-2011, 11:07 AM
Problem with update_batch() - by El Forum - 05-06-2011, 10:16 AM
Problem with update_batch() - by El Forum - 05-06-2011, 01:14 PM
Problem with update_batch() - by El Forum - 05-06-2011, 02:03 PM
Problem with update_batch() - by El Forum - 05-09-2011, 08:50 AM
Problem with update_batch() - by El Forum - 05-09-2011, 08:57 AM
Problem with update_batch() - by El Forum - 05-09-2011, 11:49 AM
Problem with update_batch() - by El Forum - 05-09-2011, 12:21 PM
Problem with update_batch() - by El Forum - 05-09-2011, 12:39 PM
Problem with update_batch() - by El Forum - 05-09-2011, 12:43 PM



Theme © iAndrew 2016 - Forum software by © MyBB