我正在为我的模型添加一个数组。 Say数组的值为1和2.
现在我需要将其更新为单个列1,2,以便该列看起来像这样
列
1,2
foreach($x as $y){
$this->db->where('column',4);
$this->db->set('id',$data);
$this->db->update('table');
}
但这只是更新2,省略1.我在哪里错了?
答案 0 :(得分:0)
使用implode
例如:
$data = [1,2]
$comma_data = implode(",", $data)
然后使用$comma_data
答案 1 :(得分:0)
如果要在列中保存多个值,请将它们放入 一个数组并序列化它们。比保存在列中。 使列类型为文本。
$array['name'] = 'test';
$array['otherinfo'] = 'otherinfo';
$data = serialize($array);
foreach($x as $y)
{
$this->db->where('column',4);
$this->db->set('id',$data);
$this->db->update('table');
}
当您选择时,可以使用unserialize();
反序列化数组答案 2 :(得分:0)
我的数据类型错误,我想出来了。