Where子句CodeIgniter中的活动记录问题

时间:2017-06-27 12:09:26

标签: php database codeigniter-3

我在下面写了活动记录

$query = $this->db->from('tbl_restaurant as tr, tbl_restaurant_servicearea as trs, tbl_restaurant_cuisines as trc')
                          ->where('tr.id', 'trs.restaurant_id')
                          ->where('tr.id', 'trc.restaurant_id')
                          ->where('trs.servicearea_subujrb', $search_suburb)
                          ->get();

生成以下提供0行的查询。

SELECT * FROM `tbl_restaurant` as `tr`, `tbl_restaurant_servicearea` as `trs`, `tbl_restaurant_cuisines` as `trc` WHERE `tr`.`id` = 'trs.restaurant_id' AND `tr`.`id` = 'trc.restaurant_id' AND `trs`.`servicearea_subujrb` = '753010 - Cuttack'

但查询应该看起来像我们将获得表中的行。

SELECT * FROM tbl_restaurant as tr, tbl_restaurant_cuisines as trc, tbl_restaurant_servicearea trs WHERE tr.id = trs.restaurant_id and tr.id = trc.restaurant_id and trs.servicearea_suburb = '".$search_suburb."'

我认为问题出现在where子句中的“ID”,其中back tick是数据库表中的整数。如果我们删除后面的刻度,那么结果显示正确。

请提供解决方案,以便结果返回该查询的正确行。

我知道我是否会使用$ this-> db-> query();然后我会得到解决方案,但我想使用有效记录。

提前致谢

1 个答案:

答案 0 :(得分:0)

解决:

$query = $this->db->from('tbl_restaurant as tr, tbl_restaurant_servicearea as trs, tbl_restaurant_cuisines as trc')
                          ->where('tr.id = trs.restaurant_id')
                          ->where('tr.id = trc.restaurant_id')
                          ->where('trs.servicearea_subujrb', $search_suburb)
                          ->get();