更新 Codeigniter 中的多行 [英] Update multiple Rows in Codeigniter
问题描述
我一直在四处寻找,但我还没有找到答案.如果您知道答案,请提供帮助.
I have been looking around but I have not found an answer yet. Kindly help if you know the answer.
如何更新 CI 中的多行?
How do you update multiple rows in CI?
在我的 MySQL 中:
In my MySQL:
我有列名:
ID, Settings Name, Settings Value ( Settings Name is Unique )
我有 ff 数据:
ID = 1, Settings Name = "Hello" , Settings Value = "True"
ID = 2, Settings Name = "World", Settings Value = "Good"
还有更多...
我还有一个获取 Settings Value
的表单,但我不确定如何在数据库上更新它.如何更新 Hello
的 True
作为 Settings Name
并更新 Good
的 World
.
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
.
我听说过 insert_batch()
但有 update_batch()
吗?
I heard about insert_batch()
but is there an update_batch()
?
推荐答案
你用的是Active Record吗?
Are you using Active record?
是的,有一个更新批次:$this->db->update_batch();
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');
来自文档:
第一个参数将包含表名,第二个是一个关联数组,第三个参数是 where 键.
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屋!