简体   繁体   English

Where子句CodeIgniter中的Active Record问题

[英]Active Record Issue in Where clause CodeIgniter

I have written this below active records 我已经在活动记录下面写了这个

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

That Generates the below query which provides 0 rows. 生成下面的查询,其中提供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'

But query should look like this show that we will get the rows in our table. 但是查询应该看起来像这样,表明我们将在表中获取行。

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."'

I think the issue is in "ID" in where clause with back tick which is integer in database table. 我认为问题出在带反勾号的where子句中的“ ID”中,后者是数据库表中的整数。 If we are removing the back ticks then the result showing correct. 如果我们删除了反向滴答声,那么结果将显示正确。

Please provide a solution so that the result will return the correct rows for that query. 请提供解决方案,以便结果将返回该查询的正确行。

i know if i will use the $this->db->query(); 我知道我是否会使用$ this-> db-> query(); then i will get the solution but i want to use active records. 然后我将获得解决方案,但我想使用活动记录。

Thanks in advance 提前致谢

Solved: 解决了:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM