如何在codeigniter上获取我的ID?

时间:2018-01-29 03:19:50

标签: php codeigniter insert-id

Struckuter 所以当我在tproject上输入blablabla时,我想要从id项目到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');

MODEL

function input_data($data,$table){
  $this->db->insert($table, $data);
  $id = $this->db->insert_id();
  return (isset($id)) ? $id : FALSE;
}

1 个答案:

答案 0 :(得分:0)

成功在项目表中插入数据时,将返回的值存储在变量中

$project_id=$this->main_model->input_data($data,'tproject');

将该数据存储在$ data1数组中:

$data1 = array (
'pid' => $project_id,
'uid' => $uid,
'title'=> "user"
);

并将其插入:

$this->main_model->input_data($data1,'tproject_pic');