php - Codeigniter join() not working -
i trying run query using codeigniter framework. want avoid using clause, , instead have included condition part of on clause in join statement of query. far more efficient since join statement executed before clause. here code:
$this->db->select('sql_calc_found_rows projects.id, projects.project_name, projects.date_modified, projects.last_modifier, projects.status, project_users.permission', false)-> from('projects'); $this->db->join('project_users', 'project_users.id = projects.id , project_users.user_id = ' . $this->user_id); if ($orderby !== false) { $this->db->order_by($orderby, $direction); } if ($limit !== null) { $this->db->limit($limit, $offset); } $query = $this->db->get();
when attempt load page, receive sql error. seems codeigniter not including condition after and:
select sql_calc_found_rows projects.id, projects.project_name, projects.date_modified, projects.last_modifier, projects.status, project_users.permission (`projects`) join `project_users` on `project_users`.`id` = `projects`.`id` , order `project_name` asc limit 5, 0
join('project_users', 'project_users.id = projects.id , project_users.user_id = ' . $this->user_id);
should be
$this->db->join('project_users', 'project_users.id = projects.id , project_users.user_id = ' . $this->user_id);
Comments
Post a Comment