• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[3.1.5] Update Batch and Where Problems

#1
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, 07: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
(07-30-2017, 07: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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.