提问人:Reza Alvaero 提问时间:1/29/2018 最后编辑:Kasia GogolekReza Alvaero 更新时间:1/29/2018 访问量:53
如何在codeigniter上获取我的ID?
How to get my ID on codeigniter?
问:
斯特鲁特所以我想要当我在 tproject 上输入 blablabla 时,从 id project 到 tproject_pic 的自动 id,但是当我使用 blabla 时,tproject_pic上没有记录,这是错误的吗?
控制器
$data = array(
'id' => '',
'division' => $division,
'client'=> $client,
'siteid' => $siteid,
'sitename' => $sitename,
'lat' => $lat,
'lng' => $lng,
'location' => $location,
'address' => $address,
'description' => $description,
'account' => $account,
'datestart' => $datestart,
'dateclose' => $dateclose,
'pono' => $pono,
'podate' => $podate,
'povalue' => $povalue,
'status' => $status,
'status_remark' => $status_remark,
'datestamp' => date('YmdHis')
);
$data1 = array (
'pid' => $id,
'uid' => $uid,
'title'=> "user"
);
helper_log("add", "menambahkan data");
$this->form_validation->set_rules('siteid', 'Site ID', 'trim|required|alpha_dash|xss_clean|callback_checksite');
//$data['client_dropdown'] = $this->main_model->client_dropdown;
$this->session->set_flashdata('message','<div class="teal">Data telah di update</div>');
$this->main_model->check_site($siteid);
$this->main_model->input_data($data,'tproject');
$this->main_model->input_data($data1,'tproject_pic');
print_r($data1);
exit;
$data['dd_client'] = $this->main_model->dd_client();
$data['dd_lokasi'] = $this->main_model->dd_lokasi();
redirect('page/master');
型
function input_data($data,$table){
$this->db->insert($table, $data);
$id = $this->db->insert_id();
return (isset($id)) ? $id : FALSE;
}
答:
1赞
yaxe
1/29/2018
#1
在项目表中成功插入数据后,将返回值存储在变量中,例如
$project_id=$this->main_model->input_data($data,'tproject');
并将该 ID 存储在 $data 1 数组中,如下所示:
$data1 = array (
'pid' => $project_id,
'uid' => $uid,
'title'=> "user"
);
并将其插入为:
$this->main_model->input_data($data1,'tproject_pic');
评论
echo $this->db->last_query();