我想按照字母顺序升序显示学生列表。假设,学生姓名首先获得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; ?>
答案 0 :(得分:0)
只需按优先级列出“订购依据”字段。升序是默认值,因此您无需指定。
$query = $this->db->query("SELECT * FROM $table order by grade, name");