CodeIgniter Forums
[3.1.5] Update Batch and Where Problems - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17)
+--- Thread: [3.1.5] Update Batch and Where Problems (/showthread.php?tid=68561)



[3.1.5] Update Batch and Where Problems - rodrigoprazim - 07-27-2017

Hi,

I have the following Scenario:
Code:
public function update_data($data=NULL){
     $this->db->where('status','1');
     $this->db->update_batch('tb_fone',$data,'user_id');
}

I have over 100 data to be updated, so, the top 100 look like this:
Code:
// Produces: 
// UPDATE `tb_fone` SET `name` = CASE
// WHEN `column` = 'My title' THEN 'My Name 2'
// WHEN `column` = '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')
// AND `status` = '1';

However, the next data is missing WHERE:
Code:
// Produces: 
// UPDATE `tb_fone` SET `name` = CASE
// WHEN `column` = 'My title' THEN 'My Name 2'
// WHEN `column` = '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');



RE: [3.1.5] Update Batch and Where Problems - jarmen_kell - 07-27-2017

(07-27-2017, 06:08 PM)rodrigoprazim Wrote: Hi,

I have the following Scenario:
Code:
public function update_data($data=NULL){
     $this->db->where('status','1');
     $this->db->update_batch('tb_fone',$data,'user_id');
}

I have over 100 data to be updated, so, the top 100 look like this:
Code:
// Produces: 
// UPDATE `tb_fone` SET `name` = CASE
// WHEN `column` = 'My title' THEN 'My Name 2'
// WHEN `column` = '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')
// AND `status` = '1';

However, the next data is missing WHERE:
Code:
// Produces: 
// UPDATE `tb_fone` SET `name` = CASE
// WHEN `column` = 'My title' THEN 'My Name 2'
// WHEN `column` = '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');

Have you tried method chaining?
PHP Code:
<?php
public function update_data($data=NULL){
[
size=small][font=MonacoConsolasCouriermonospace]     $this->db->where('status','1')[/font][/size][size=small]->update[/size][size=small]_batch('tb_fone',$data,'user_id');[/size]
}
?>



RE: [3.1.5] Update Batch and Where Problems - rodrigoprazim - 07-30-2017

Yes, go through something.


RE: [3.1.5] Update Batch and Where Problems - jarmen_kell - 07-30-2017

(07-30-2017, 06:12 AM)rodrigoprazim Wrote: Yes, go through something.

you might wanna ask more on CI's Slack channel instead:
codeigniterchat.slack.com

the way this forum moderate my reply for you before being published
in much too long time (in 24 hours) kind of inconvenient.

use this URL to to retrieve an invitational link. it's instantaneous.
http://codeignitersignup.ciblox.com/