Reputation: 13545
I would like to check whether r.is_show_map = 1, if true, then return r.lat, otherwise, return null
Here is the code
$this->db->select('r.*, IF(r.is_show_map = 1, r.lat, null) as r.lat', false);
The problem is it caused the syntax error
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.lat FROM (`request` as r) WHERE `r`.`adv_type` != 0 AND `r`.`is_delete` = 0 AN' at line 1
SELECT r.*, IF(r.is_show_map = 1, r.lat, null) as r.lat FROM (`request` as r) WHERE `r`.`adv_type` != 0 AND `r`.`is_delete` = 0 AND NOW() <= DATE_ADD(r.create_date, INTERVAL 15 DAY)
How to fix it? Thanks
Upvotes: 0
Views: 173
Reputation: 23719
Try this:
$this->db->select('r.*, IF(r.is_show_map = 1, r.lat, null) as lat', false);
Upvotes: 1