【发布时间】:2019-11-08 00:27:12
【问题描述】:
我想使用CodeIgniter从数据库中获取数据。
function fetch_chapter()
{
$this->db->select('*');
$this->db->from("chapter");
$this->db->join('unit', 'unit.unit_number = chapter.unit_number', 'left');
$this->db->order_by('chapter.unit_number', 'ASC');
$this->db->order_by('chapter_number', 'ASC');
$query = $this->db->get();
return $query;
}
我想要如下结果:
Unit 1
Chapter 1
Lesson 1
Lesson 2
Chapter 2
Lesson 1
Unit 2
Chapter 1
Lesson 1
Chapter 2
Lesson 1
【问题讨论】:
-
$this->db->distinct();使用这条线
-
$this->db->group_by("column_name");
-
当我使用 group_by 时,每个单元只返回 1 个章节。
-
您的问题需要更多关注(它太宽泛了)。请注意您是如何寻求模型帮助的,然后在 cmets 中,您需要控制器帮助。这是志愿者不喜欢陷入的一种场景,因为它是“永无止境的问题”,也就是“请给我写一个完整的教程”。
标签: php mysql sql codeigniter