$this->db->update_batch ();
Generating an update command is based on the data you provide and executes the query. You can pass an array or an object's arguments to the Update_batch () function. The following is an example of using an array as a parameter: generates an update string based on the data supply, and runs the query. You can either pass a array or an object to the function. A example using an array:
1 $data=Array(2 Array(3' Title ' = ' My title ',4' Name ' = ' My name 2 ',5' Date ' = ' My date 2 '6),7 Array(8' Title ' = ' Another title ',9' Name ' = ' Another Name 2 ',Ten' Date ' = ' Another date 2 ' One ) A ); - - $this->db->update_batch (' MyTable ',$data, ' title '); the - //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 A //when ' title ' = ' My title ' Then ' My date 2 ' at //when ' title ' = ' Another title ' Then ' another date 2 ' - //ELSE ' date ' END - //WHERE ' title ' In (' My title ', ' another title ')
Parameter 1: Table name parameter 2: two-dimensional array parameter 3: Key name as shown above.
Tip: All values will be automatically filtered for security.
That
UPDATE ' MyTable '
SET ' name ' = case
When the ' title ' = ' My title ' Then
' My Name 2 '
When ' title ' = ' Another title ' Then
' Another Name 2 '
ELSE
' name '
END,
' Date ' = case
When the ' 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 ')
-----------------------------------------------------------
For example, to bulk update status unread read:
$data = Array (
Array
' id ' = ' 1 ',
' Status ' = ' READ '
),
Array
' id ' = ' 2 ',
' Status ' = ' READ '
)
);
$this->db->update_batch (' mytable ', $data, ' id ');
CI batch update $this->db->update_batch ();