提取数据库中的数据并合并重复的数据

我想使用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
chenglong502 回答:提取数据库中的数据并合并重复的数据

这可能是您的控制器代码:

$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; ?>" >
本文链接:https://www.f2er.com/3140921.html

大家都在问