-1
我正在研究Codeigniter,我有以下表格,我希望首先打印一個主題名稱,然後打印出所有子主題,如下所示:無法從Codeigniter的foreach循環中的兩個表中獲取記錄
主題:
-----------------------
id | Subjects Name
-----------------------
1 | Mathematics
2 | Physics
3 | Chemistry
小節:
---------------------------------------------
id | subject_id | SubsectionsName
---------------------------------------------
1 2 Electromagnetism
2 1 Algebra
3 3 Organic Chemistry
4 1 Geometry and Topology
5 2 Mechanics
我想下面的輸出
Mathematics
Algebra
Geometry and Topology
Physics
Electromagnetism
Mechanics
Chemistry
Organic Chemistry
對我使用下面的代碼,但它不給我正確的輸出。
$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;
}
@ user3653474:解決了您的問題? – AnkiiG
是AG21感謝您的支持。 – user3653474
但爲什麼-1這個問題。 – user3653474