Welcome Guest, Not a member yet? Register   Sign In
jone with three tables

Hi To All I have three tables in my database,
I have to create a query to retrieve subject name belongs to grade id.this subject and grade contain many to many relationship.
I rote a query which i copy bellow. But it retrieve grade name belong to grade id.
If any one know please help me.
(Note: I am using xajax for retrieve)
Thank You.

              $this->db->join('grade_to_sub', 'grade_to_sub.sub_id=subject.sub_id');
              $this->db->join('grade', 'grade.grd_id=grade_to_sub.grd_id');
        $res = $query->result_array();
        if ($option=='html_option')
            $list = '';
            for($x=0; $x<count($res); $x++)
                $list .= "<option value='".$res[$x]['sub_id']."'>".$res[$x]['name']."</option>";
            return $list;
            return $res;

[eluser]Georgi Budinov[/eluser]
Well this is because you have name field in both tables.
The fastest is to change $this->db->select("*"); to $this->db->select("*, subject.name");
I am not very aware with the ActiveRecord functionality as I am not using it. You can check how to set aliases for tables and please don't use * in the select - it is always better to name all the fields you want to retrieve.

Hi.. Georgi Budinov, Thank you very much.
It work now properly.

Theme © iAndrew 2016 - Forum software by © MyBB