【发布时间】:2015-09-26 11:38:16
【问题描述】:
您好,我正在使用 codeigniter。我需要获取最后插入的 id 并将其递增并在我的视图页面中使用它, 我的控制器代码:
public function add_tickets()
{
$status = $this->input->post("status_button");
$emp_array = $this->input->post("employee");
$start_array = $this->input->post("start_time");
$pid_array = $this->input->post("pid");
$total_array = $this->input->post("total");
if($status == "leave_open")
{
$button_status="open";
}
else
{
$button_status="";
}
$insert_id = $this->billing_model->store_bill($data_to_store);
/*Here I am tring to get the last inserted id*/
for ($i = 0; $i < count($pid_array); $i++) {
if(isset($pid_array[$i])&& $pid_array[$i]!=""){
$data_to_store = array(
'id' => $insert_id +1,
'employee' => $emp_array[$i],
'start_time' => $start_array[$i],
'pid' => $pid_array[$i],
'total' => $total_array[$i],
'status' => $button_status,
);
$this->billing_model->store_bill($data_to_store);
}
}
$data['ticket_new_id'] = $data_to_store['id'];
$data['bill']=$this->billing_model->get_bill();
$data['main_content'] = 'admin/billing/list';
$this->load->view('includes/template', $data);
}
这是我插入账单的控制器功能。 这是我的模型函数,
function store_bill($data)
{
$insert = $this->db->insert('bill', $data);
$insert_id = $this->db->insert_id();
return $insert_id;
}
这里我使用$this->db->insert_id() 来获取最后插入的id。
我收到这样的错误,
You must use the "set" method to update an entry.
Filename: C:\xampp\htdocs\elfanto\elfanto_billing\system\database\DB_active_rec.php
Line Number: 1174
有人可以帮助我吗?提前致谢
【问题讨论】:
-
什么是
$data_to_store变量? -
这是一个数组,我从 @AnkiiGangrade 表单中获取 post 值
-
你没有在你的代码中创建任何数组
$data_to_store!! -
在哪里使用?你能告诉我@Saty
-
$insert_id = $this->billing_model->store_bill($data_to_store);用于定义$data_to_store的这一行??
标签: mysql codeigniter