dsedug8644 2017-03-04 09:05
浏览 173

codeigniter中的update_batch

Here is my code that i used to update all the rows that am getting for that i used update_batch function but its not working properly

 public function edit_project_involved($users)
{

    foreach ($users as $v_user) {

    $data=array('involved'=>1);
    $v=$this->db->where('user_id',$v_user);
    $query=$this->db->update_batch('tbl_users',$data,$v);
    }

    if($query)
    {
        return true;
    }

}

my $users var_dump looks like this

C:\wamp64\www\spectra\application\models\Project_model.php:536:
array (size=3)
0 => string '40' (length=2)
1 => string '42' (length=2)
2 => string '37' (length=2)

am getting an error like this

One or more rows submitted for batch updating is missing the specified index.

Filename: C:/wamp64/www/spectra/system/database/DB_query_builder.php

Line Number: 2010

My table looks like this

user_id     username        involved
    1         admin           0
    36        siraj           0
    37        faizal          0
    38        nesru           0
    40        jaseer          0
    42        maltu           0
    43        shahul          0     
    44        samsheera       0

var_dump($data) looks like this

C:\wamp64\www\spectra\application\models\Project_model.php:544:
array (size=3)
0 => 
  array (size=2)
    'user_id' => string '40' (length=2)
    'involved' => int 1
1 => 
  array (size=2)
    'user_id' => string '42' (length=2)
    'involved' => int 1
2 => 
  array (size=2)
    'user_id' => string '37' (length=2)
    'involved' => int 1
  • 写回答

1条回答 默认 最新

  • douweilaton2762 2017-03-04 09:37
    关注

    You not followed the rules mentioned in documentation https://www.codeigniter.com/user_guide/database/query_builder.html

    Try this (notice update_batch outside of loop and how the array made)

    foreach ($users as $v_user) {
      $data[] = array(
       'user_id' => $v_user,
       'involved'=> 1
      );
    }
    $query = $this->db->update_batch('tbl_users',$data,'user_id');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入