-1

我需要guest_idnew_guestguest_nic_pp_dl等于变量guest_nic_pp_dlLIMIT1 个结果的表中获取。然而,我写的代码以一个愚蠢的语法错误结束。如何使用变量值定义 WHERE 以匹配行?

解析错误:语法错误,第 20 行 C:\xampp\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;
4

3 回答 3

2

像这样试试

     $query = $this->db->query("SELECT guest_id FROM new_guest WHERE guest_nic_pp_dl, '$guest_nic_pp_dl' LIMIT 1"); 
于 2013-07-07T20:19:32.890 回答
2

$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');

于 2013-07-07T20:21:44.447 回答
2
$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;
}
于 2013-07-08T09:40:27.837 回答