我收到以下错误:
遇到PHP错误
严重性:注意
消息:数组到字符串转换
文件名:models / Bulk_Recipeis_model.php
行号:32
我在模型中的代码:
public function insert_order($user, $recipies, $quantity, $date, $time, $totalbill)
{
$this->db->trans_start();
foreach($quantity as $key => $user_quantity) {
$this->db->query("UPDATE bulk_delivery SET max_quantity = max_quantity - '$user_quantity'");
$this->db->query("INSERT INTO bulk_delivery_order (id, user_quantity, date,time,total_bill,bulk_delivery_id) VALUES ('$user', '$user_quantity', '$date', '$time', '$totalbill', '$recipies')");
}
$this->db->trans_complete();
}
我在控制器中的代码:
public function get_insert_order(){
$user = $this->userId;
$recipies = $this->input->post('bulk_delivery');
$quantity = $this->input->post('quantity');
$date = $this->input->post('date');
$time = $this->input->post('time');
$totalbill = $this->input->post('bill');
$this->bulk_recipe->insert_order($user, $recipies, $quantity, $date, $time, $totalbill);
redirect('BulkRecipe_Controller');
}
在我看来,我使用的是数组数据:
<input type="hidden" name="bulk_delivery[]" value="<?php echo $row->bulk_delivery_id;?>" >
<input type="text" name="quantity[]" step="1" class="container" value="" onfocus="this.value = '';" onblur=";" style="width: 60px">
请告诉我如何解决此错误。
答案 0 :(得分:0)
将您的模型更改为此 -
public function insert_order($user, $recipies, $quantity, $date, $time, $totalbill)
{
$this->db->trans_start();
foreach($quantity as $key => $user_quantity) {
$final_quantity = $user_quantity['key'];
$this->db->query("UPDATE bulk_delivery SET max_quantity = max_quantity - '$final_quantity'");
$this->db->query("INSERT INTO bulk_delivery_order (id, user_quantity, date,time,total_bill,bulk_delivery_id) VALUES ('$user', '$final_quantity', '$date', '$time', '$totalbill', '$recipies')");
}
$this->db->trans_complete();
}