在Codeigniter中更新多个行 [英] Update multiple Rows in Codeigniter

查看:116
本文介绍了在Codeigniter中更新多个行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在看,但我还没有找到答案。



如何更新CI中的多行?





我有列名:

  ID,设置值(设置名称是唯一的)

我有ff数据:

  ID = 1,设置Name =Hello,设置值=True
ID = 2,设置Name =World Value =Good

等等...


$ b b

我也有一个窗体获得设置值,但我不知道如何在数据库上更新它。如何更新 True Hello 设置名称并为世界更新良好



我听说过 insert_batch()但是有一个 update_batch()



是否有更新批次 $ this-> db-> update_batch();

  $ data = array(
array(
'ID'=> 1,
'Settings Name'=>'Hello',
'Settings Value'=>'True'
),
array(
'ID'=>'2',
'Settings Name'=> World',
'Settings Value'=>'Good'

);

$ this-> db-> update_batch('mytable',$ data,'where_key');

从文档:

 第一个参数将包含表名,第二个是关联数组的值,第三个参数是where键。 


I have been looking around but I have not found an answer yet. Kindly help if you know the answer.

How do you update multiple rows in CI?

In my MySQL:

I have column names:

ID, Settings Name, Settings Value ( Settings Name is Unique )

I have the ff Data:

ID = 1, Settings Name = "Hello" , Settings Value = "True"
ID = 2, Settings Name = "World", Settings Value = "Good"

and more ...

I also have a form that gets the Settings Value but I am not sure how to update it on the DB. How to update the True for the Hello being the Settings Name and update the Good for the World.

I heard about insert_batch() but is there an update_batch()?

解决方案

Are you using Active record?

Yes there is an update batch: $this->db->update_batch();

$data = array(
array(
  'ID' => 1 ,
  'Settings Name' => 'Hello' ,
  'Settings Value' => 'True'
),
array(
  'ID' => '2' ,
  'Settings Name' => 'World' ,
  'Settings Value' => 'Good'
)
);    

$this->db->update_batch('mytable', $data, 'where_key'); 

From the documentation:

The first parameter will contain the table name, the second is an associative array of values, the third parameter is the where key.

这篇关于在Codeigniter中更新多个行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆