[英]CodeIgniter: LEFT JOIN in $this->db->query returns a database error
[英]CodeIgniter: Query with WHERE returns an error :: $query = $this->db->query()
我需要从new_guest
表中获取guest_id
,其中guest_nic_pp_dl
列等于变量guest_nic_pp_dl
并将LIMIT
为1。 但是,我编写的代码以愚蠢的语法错误结尾。 如何定义带有变量值的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;
这样尝试
$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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.