【发布时间】:2017-06-13 01:10:55
【问题描述】:
是否可以在codeigniter的mysql查询中传递变量值?
我想从数据库中选择 ID 与我的会话 ID 相同的记录。
我的代码是:
$this->db->select('*'); // <-- There is never any reason to write this line!
$this->db->from('products');
$this->db->where('id_admin = (SELECT id_admin FROM users WHERE id='.$this->session->userdata('user_id').')', NULL, TRUE);
我们可以在数据库查询中连接变量值吗?
这段代码没有给出任何错误,但也没有给出任何结果。
【问题讨论】:
-
利用join。
-
尝试如下答案。
标签: php mysql codeigniter