[eluser]shahmy[/eluser]
Hi To All I have three tables in my database,
1.subject
2.grade
3.sub_to_grade.
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.
Code:
$this->db->select("*");
$this->db->from('subject');
$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');
$this->db->where(array('grade.grd_id'=>$grd_id));
$query=$this->db->get();
}
$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;
}
else
{
return $res;
}