Welcome Guest, Not a member yet? Register   Sign In
$this->db->distinct() help needed
#1

[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.
#2

[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.




Theme © iAndrew 2016 - Forum software by © MyBB