使用编码器按字母顺序显示数组


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");