使用 Codeigniter 按字母顺序显示数组

Display array in Alphabetically order Using Codeigniter

我想根据成绩按字母升序显示学生名单。假设,先显示获得A的学生姓名,然后显示获得B的学生。我试过但它不是按字母顺序显示。

感谢您的帮助。

My code
controller:

function showResult(){

         $data['count']=$this->data_Model->getStudent('result');


        $this->load->view('section',$data); 

      } 
Model:
    public function getStudent($table) {


      $query = $this->db->query("SELECT * FROM $table order by grade asc");

          return $query->result_array();

    }

View

section.php
            <?php 
               foreach($count as $student):

                  echo $student['name']; 
                  echo $student['grade'];
              endforeach; ?>

只需按优先级列出 "order by" 字段。升序是默认值,因此您不必指定它。

$query = $this->db->query("SELECT * FROM $table order by grade, name");