简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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