php - 获取数据库中的数据并合并重复数据
问题描述
我想使用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->load->model('modelname');
$data['s'] = $this->modelname->fetch_chapter();
$this->load->view('foldername/filename', $data, FALSE);
您的型号代码:
function fetch_chapter()
{
$this->db->select('*');
$this->db->distinct( );
$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->row();
}
您在每个文本框中查看页面代码:
<input type="text" value="<?php echo $s->fieldname; ?>" >
推荐阅读
- javascript - 为什么正则表达式在表单输入上不正确。Javascript
- python - 无法在 Django 中导入 xlsx 编写器
- python-3.x - 工作 xml 数据 - 在 Python 中提取部分字符串
- google-apps-script - Google 脚本创建事件 - 事件描述问题
- javascript - 来自csv的c3 js饼图
- react-native - 使用 aws-amplify-react-native 注册时未收到确认码(之前突然失败的作品)
- php - PHP删除匹配模式或通配符模式的标签
- css - 条纹支付选择样式
- javascript - jQuery - 查找同一父行的另一个子元素值
- c# - MsiTriState LinkToFile和MsiTriState SaveWithDocument是什么意思在添加图片到excel C#