CodeIgniter Forums
$this->db->distinct() help needed - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: $this->db->distinct() help needed (/showthread.php?tid=8255)



$this->db->distinct() help needed - El Forum - 05-12-2008

[eluser]Computerzworld[/eluser]
Hello. I want to use $this->db->distinct on a particular column lets say trainId. How can I use it? I have passed trainId as parameter like this. $this->db->distinct('trainId') but it didn't returned me distinct result. Here is the exact code which I have written.
Code:
$this->db->distinct('trainId');
$this->db->where_in('stationId', $stationIds);
$query = $this->db->get("tbl_tt_schedule");
Please help me. Thanks in advance.


$this->db->distinct() help needed - El Forum - 05-12-2008

[eluser]gtech[/eluser]
you don't pass a parameter like that into distinct..
this is the function in the active record code
Code:
function distinct($val = TRUE)
    {
        $this->ar_distinct = (is_bool($val)) ? $val : TRUE;
        return $this;
    }
when it runs the sql statement it uses the following line of code
Code:
$sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT ';

so distinct only takes TRUE or FALSE as a parameter, and the default is TRUE if nothing is passed in.

hope this helps you.