Welcome Guest, Not a member yet? Register   Sign In
[3.1.5] Update Batch and Where Problems
#1

(This post was last modified: 07-27-2017, 06:08 PM by rodrigoprazim.)

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');
Reply
#2

(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]
}
?>
Reply
#3

Yes, go through something.
Reply
#4

(This post was last modified: 07-30-2017, 04:48 PM by jarmen_kell. Edit Reason: forgot the slack channel invitational link url )

(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/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB