【发布时间】:2011-12-05 06:19:58
【问题描述】:
我想用foreach 更新数据库表中的几行,但出现以下错误:
这是我的 php 代码:
$id_units = $this->input->post('id_units');
$name_un = $this->input->post('name_units');
$price_un = $this->input->post('price_units');
$description_un = $this->input->post('explanation_units');
$ex_un = $this->input->post('addition_units');
$service_un = $this->input->post('checkbox_units');
$data2 = array();
foreach ($name_un as $idx => $name) {
$data2 = array(
'relation' => $id_residence,
'name_un' => $name_un[$idx],
'price_un' => $price_un[$idx],
'description_un' => $description_un[$idx],
'ex_un' => $ex_un[$idx],
'service_un' => json_encode($service_un[$idx]), // This Is Line Number: 212
);
$this->db->update('hotel_units', $data2, array('id' => $id_units[$idx]));
};
上面的代码有这个错误:
发生数据库错误
错误号:1054
未知列 'where 子句'中的'数组'
UPDATEhotel_unitsSET0= 数组 WHEREid= 数组
文件名: D:\xampp\htdocs\system\database\DB_driver.php
行号:330
更新:
我有新的错误:
遇到 PHP 错误
严重性:通知
消息: 未定义的偏移量:1
文件名:residence.php
行号: 212遇到 PHP 错误
严重性:通知
消息:未定义的偏移量:2
文件名:residence.php
行 号码:212遇到 PHP 错误
严重性: 注意
消息:未定义的偏移量:3
文件名: Residence.php
行号:212
'service_un' =>... 是复选框。请参阅上述 php 代码中的行号:212
【问题讨论】:
标签: php arrays codeigniter