CodeIgniter Forums
distinct problem - 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: distinct problem (/showthread.php?tid=38846)



distinct problem - El Forum - 02-21-2011

[eluser]Bigil Michael[/eluser]
is it possible to list the distinct names from 3 columns of the same table?????

can anyone help me???? urgent

thanks in advance....


distinct problem - El Forum - 02-21-2011

[eluser]Rok Biderman[/eluser]
Distinct normally doesn't work that way, but it' s easy to run 3 separate queries in the model function and then assign all 3 arrays to result.


distinct problem - El Forum - 02-21-2011

[eluser]Bigil Michael[/eluser]
can u help me

these are the three columns
Code:
id  tour_type1  tourtype2  tourtype3
1      A          B           C
2      B          C           D
3      D          E           F

i want to list the distinct values that is
A
B
C
D
E
F
how will i do this can u help me??
thanks in advance.


distinct problem - El Forum - 02-22-2011

[eluser]Rok Biderman[/eluser]
Now, i'm sure that there are a more elegant ways to do this, but this one works as well.

Code:
function oneatatime($args)
    {
        
        $this->db->distinct();
        $this->db->select($args);
        $query = $this->db->get('narocniki');
        return $query->result();
    }

function alldatainsinglearray()
    {
        $myarray = array();
        $tour_type1 = ($this->oneatatime('tour_type1'));
        foreach ($tour_type1 as $item):
        array_push($myarray, $item->tour_type1);
            endforeach;
        $tour_type2 = ($this->oneatatime('tour_type2'));
        foreach ($tour_type2 as $item):
        array_push($myarray, $item->tour_type2);
            endforeach;
        $tour_type3 = ($this->oneatatime('tour_type3'));
        foreach ($tour_type3 as $item):
        array_push($myarray, $item->tour_type3);
            endforeach;
        return $myarray;
    }

Hope it helps.