Codeigniter从声明的变量发布数据


function index_post() {
$sql = "SELECT id_so FROM so_detail ORDER BY id_so DESC LIMIT 1";
$last_id2 = $this->db->query($sql)->result();
foreach ($last_id2 as $row) {
$last_id = $row->id_so;
}
//echo $last_id;
$data = array(
'id_so'      => $this->post($last_id),
'id_product' => $this->post('id_product'),
'harga'      => $this->post('harga'),
'harga_dasar'=> $this->post('harga'),
'modal'      => $this->post('modal'),
'pajak'      => $this->post('pajak'),
'qty'        => $this->post('qty'),
'keterangan' => $this->post('keterangan'),
'create_user'=> $this->post('create_user'),
'create_time'=> $this->post('create_time'),
'update_user'=> $this->post('create_user'),
'update_time'=> $this->post('create_time'));
$insert = $this->db->insert('so_detail', $data);
if ($insert) {
$this->response($data, 200);
} else {
$this->response(array('status' => 'fail', 502));
}
}

我遇到了一个问题,发布的idso是"null"。当我回显$last_id时,它显示正确的id ex:120。但当我将其调用为$this->post($last_id(时,它只是null。。

如何使用之前已经声明的字符串($last_id(发布id_so??

$last_id2变量中有很多数组。data会根据您的last_id2插入多次。试试这个:

foreach ($last_id2 as $row) {
$data = array(
'id_so'      =>$row->id_so,
'id_product' => $this->post('id_product'),
'harga'      => $this->post('harga'),
'harga_dasar'=> $this->post('harga'),
'modal'      => $this->post('modal'),
'pajak'      => $this->post('pajak'),
'qty'        => $this->post('qty'),
'keterangan' => $this->post('keterangan'),
'create_user'=> $this->post('create_user'),
'create_time'=> $this->post('create_time'),
'update_user'=> $this->post('create_user'),
'update_time'=> $this->post('create_time'));
}
$this->db->insert_batch('so_detail',$data);

相关内容

  • 没有找到相关文章

最新更新