我想使用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; ?>" >