我刚刚使用CI查询构建器在mysql中添加了数据。现在我需要检索那些数据(行)的主键(Track Code)。我同时使用了insert和select查询,但它没有用。
型号:
public function complainReg($cName,$vName,$Email,$Contact,$date,$Complain,$ip)
{
$data = array(
'cName' => $cName,
'vName' => $vName,
'Email' => $Email,
'Contact' => $Contact,
'Date' => $date,
'Complain' => $Complain,
'ip' => $ip
);
$sql= $this->db->set($data)->get_compiled_insert('tbl_complain');
$q=$this->db->query($sql);
return $q;
}
控制器:
public function index()
{
if (isset($_POST['btnRegister']))
{
$cName=$this->input->post('cName');
$vName=$this->input->post('vName');
$Email=$this->input->post('email');
$Contact=$this->input->post('phone');
$date=$this->input->post('Date');
$Complain=$this->input->post('complain');
$ip=file_get_contents("http://ipecho.net/plain");
$this->HamroSamajModel->complainReg($cName,$vName,$Email,$Contact,$date,$Complain,$ip);
$this->session->set_flashdata("message","Your complain has been registered sucessfully");
}
$this->load->view('Complain/index');
}
答案 0 :(得分:2)
如果您需要最后一个插入ID,请尝试使用
public function complainReg($cName,$vName,$Email,$Contact,$date,$Complain,$ip)
{
$data = array(
'cName' => $cName,
'vName' => $vName,
'Email' => $Email,
'Contact' => $Contact,
'Date' => $date,
'Complain' => $Complain,
'ip' => $ip
);
$this->db->insert('tbl_complain', $data);
$lastID = $this->db->insert_id();
return $lastID;
}