我需要从new_guest
表中获取guest_id
,其中列guest_nic_pp_dl
等于变量guest_nic_pp_dl
,LIMIT
等于1的结果。然而,我写的代码以一个愚蠢的语法错误结束。如何使用变量值定义WHERE以匹配行?
分析错误:语法错误,第20行上C:''examplep''htdocs''bit''application''models''reservations_model.php中出现意外的"$guest_nic_pp_dl"(T_VARIABLE)
$query = $this->db->query('SELECT guest_id FROM new_guest WHERE guest_nic_pp_dl, '$guest_nic_pp_dl' LIMIT 1'); // Line 20
foreach ($query->result() as $row) {
return $row->guest_id;
像一样尝试
$query = $this->db->query("SELECT guest_id FROM new_guest WHERE guest_nic_pp_dl, '$guest_nic_pp_dl' LIMIT 1");
$this->db->select('guest_id');
$this->db->where('guest_nic_pp_dl', $guest_nic_pp_dl);
$this->db->limit(1);
$query = $this->db->get('new_guest');
$query = $this->db->query('SELECT guest_id FROM new_guest WHERE guest_nic_pp_dl='.$guest_nic_pp_dl.' LIMIT 1');
foreach ($query->result() as $row) {
return $row->guest_id;
}