Group By Three columns doesn't work in CodeIgniter Group By Three columns doesn't work in CodeIgniter codeigniter codeigniter

Group By Three columns doesn't work in CodeIgniter


In codeigniter group_by() works with two fields only.


$this->db->group_by()

Permits you to write the GROUP BY portion of your query:

$this->db->group_by(array("title", "date"));  // Produces: GROUP BY title, date

CI 3 group_by()


Edit 01

$query=$this->db->query("        SELECT `trk`.`userid` AS user_id, `scr`.`course` AS course_id         FROM `mdl_scorm` scr         INNER JOIN `mdl_scorm_scoes_track` trk         ON `scr`.`id` = `trk`.`scormid`         INNER JOIN `mdl_course_modules` mcs         ON `mcs`.`instance` = `scr`.`id`         WHERE `trk`.`value` IN ('completed', 'incomplete', 'passed')         GROUP BY `scr`.`course`, `trk`.`userid`, `trk`.`scormid`         ORDER BY `trk`.`userid`         DESC LIMIT 0,100;");$result = $query->result_array();return $result;


Consider a raw query in the model.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');class xyz_model extends CI_Model{     function __construct()     {          // Call the Model constructor          parent::__construct();     }     function get_this_thing($month,$year)      {    $myQuery="SELECT `trk`.`userid` AS user_id, `scr`.`course` AS course_id           FROM `mdl_scorm` scr           INNER JOIN `mdl_scorm_scoes_track` trk           ON `scr`.`id` = `trk`.`scormid`           INNER JOIN `mdl_course_modules` mcs           ON `mcs`.`instance` = `scr`.`id`           WHERE `trk`.`value` IN ('completed', 'incomplete', 'passed')           GROUP BY `scr`.`course`, `trk`.`userid`, `trk`.`scormid`           ORDER BY `trk`.`userid`           DESC LIMIT 0,100;";          $query = $this->db->query($myQuery);          $result = $query->result();          return $result;     }}


You can also pass an array of multiple values as well:

$this->db->group_by(array("title", "date"));  // Produces: GROUP BY title, date

Source link