CodeIgniter Forums
Escaping query - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Escaping query (/thread-22385.html)



Escaping query - El Forum - 09-08-2009

[eluser]Bnoe[/eluser]
I try this query with ar
Code:
$this->db->having('distance <=',100 * 1.609344,FALSE);
        $this->db->where('j.status','open');
        $this->db->select(" j.*, group_concat(DISTINCT et.name) as employment_types,"
                            ." group_concat(DISTINCT c.name ) as categories,"
                            ." distance(j.location_latitude, j.location_longitude, ".$latitude.", ".$longitude.") as distance"
        )->from('job j')->limit(1);
            $this->db->group_by('j.id');
        $this->db->join('job_employment_type_relation jetr','jetr.job_id = j.id');
        $this->db->join('employment_type et','et.id=jetr.employment_type_id');
        $this->db->join('job_category_relation jcr','jcr.job_id = j.id');
        $this->db->join('category c','c.id=jcr.category_id');

and i got
Code:
SELECT `j`.*, group_concat(DISTINCT et.name) as employment_types, group_concat(DISTINCT c.name ) as categories, distance(j.location_latitude, `j`.`location_longitude`, `0`, `0)` as distance FROM (`job` j) JOIN `job_employment_type_relation` jetr ON `jetr`.`job_id` = `j`.`id` JOIN `employment_type` et ON `et`.`id`=`jetr`.`employment_type_id` JOIN `job_category_relation` jcr ON `jcr`.`job_id` = `j`.`id` JOIN `category` c ON `c`.`id`=`jcr`.`category_id` WHERE `j`.`status` = 'open' GROUP BY `j`.`id` HAVING distance <= 160.9344 LIMIT 1

see : distance(j.location_latitude, `j`.`location_longitude`, `0`, `0)`

but wen we add space before ) it parsed well