首页 > 解决方案 > 对列中的数据进行排序

问题描述

嗨,我有下一个代码:

  <?php
   $homeworks = $this->db->get_where('teme', array('school_id' => school_id(), 'status'=>'0'))->result_array();
  foreach( $homeworks  as $homework){

      ?>
      <tr>
        <td><?php echo $homework['teme_code']; ?></td>
        <td><?php echo $homework['timestamp']; ?></td>
        <td>

输出是:

| teme_code| timestamp|
| XX| 01.01.2020| 
| XY| 03.01.2020| 
| XZ| 02.01.2020|

但我想展示

| teme_code| timestamp|
| XX| 01.01.2020| 
| XZ| 02.01.2020| 
| XY| 03.01.2020| 

我尝试但不工作。

$query = $this->db->query('SELECT teme_code, status=0,timestamp FROM teme ORDER BY timestamp ASC');
foreach ($query->result_array() as $row)
{...

标签: phpcodeigniter

解决方案


GROUP BYORDER BY. 尝试这个

$query = $this->db->query('SELECT teme_code, timestamp FROM teme ORDER BY timestamp ASC');
foreach ($query->result_array() as $row)
{...

推荐阅读