So I'm trying to loop through all the values of tables, which connect by ids. There are 4 tables involved, and I am trying to get all the values from each according the id of the first table. Here is the code I have so far. (P.S I'm using CodeIgniter's database method)
$course = $this->db->query("SELECT * FROM courses");
// Put Courses into array
foreach ($course->result() as $row)
{
$courses['id'] = $row->id;
$courses['course_name'] = $row->course_name;
// Put Topics into array
$topic = $this->db->query("SELECT * FROM course_topics WHERE course_id = 5");
foreach ($topic->result() as $row)
{
$topics[] = array(
'id' => $row->id,
'course_id' => $row->course_id,
'topic_name' => $row->topic_name,
'order' => $row->order
);
// Put badges into array
$badge = $this->db->query("SELECT * FROM course_topic_badges WHERE topic_id = ".$row->id);
foreach ($badge->result() as $row)
{
$badges[] = array(
'id' => $row->id,
'topic_id' => $row->topic_id,
'badge_name' => $row->badge_name
);
// Put dotpoints into array
$dotpoint = $this->db->query("SELECT * FROM course_topic_dotpoints WHERE badge_id = ".$row->id);
foreach ($dotpoint->result() as $row)
{
$dotpoints[] = array(
'id' => $row->id,
'badge_id' => $row->badge_id,
'dotpoint' => $row->dotpoint,
'viddler_video_id' => $row->viddler_video_id,
'viddler_openurl' => $row->viddler_openurl,
'order' => $row->order
);
}
}
}
}
I've been fiddling around for a while so there may be some lines that aren't done in the best fashion :)
So basically I need to iterate through the array later, but I'm just not sure of the best method of actually filling it to begin with.
Thanks for the help!!