I am working on Codeigniter and i have following tables, i want that first one subject name to be printed then all its sub-subjects and so on as given below :
Subjects:
-----------------------
id | Subjects Name
-----------------------
1 | Mathematics
2 | Physics
3 | Chemistry
Subsections:
---------------------------------------------
id | subject_id | SubsectionsName
---------------------------------------------
1 2 Electromagnetism
2 1 Algebra
3 3 Organic Chemistry
4 1 Geometry and Topology
5 2 Mechanics
I want following output
Mathematics
Algebra
Geometry and Topology
Physics
Electromagnetism
Mechanics
Chemistry
Organic Chemistry
for that i am using following code but it is not giving me correct output.
$condition = "id =" . "'" . $subject_id . "'";
$this->db->select('*');
$this->db->from('subject');
$this->db->where($condition);
$query = $this->db->get();
if ($query->num_rows() > 0) {
foreach($query->result_array() as $row)
{
$rows[] = $row;
$condition = "subject_id =" . "'" . $row['id'] . "'";
$this->db->select('*');
$this->db->from('subsections');
$this->db->where($condition);
$query_course_material = $this->db->get();
foreach($query->result_array() as $row1)
{
$rows[] = $row1;
}
}
return $rows;
} else {
return false;
}