php - 对列中的数据进行排序
问题描述
嗨,我有下一个代码:
<?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)
{...
解决方案
你GROUP BY
对ORDER BY
. 尝试这个
$query = $this->db->query('SELECT teme_code, timestamp FROM teme ORDER BY timestamp ASC');
foreach ($query->result_array() as $row)
{...
推荐阅读
- java - 创建类层次结构时,构成层次结构的类的构造函数按什么顺序调用?
- javascript - api调用者可以访问res.locals吗?
- wordpress - 我想在 wordpress 的后期编辑屏幕上维护保存在类别或自定义分类术语选择上的顺序
- sql - 在 SQL 中声明表时出现语法错误
- react-native - 单击输入时反应本机如何获取输入
- r - Zelen 精确测试 - 尝试在函数 zelen.test() 中使用 ak 2x2
- cloudinary - Cloudinary 迁移和 Rails 主动存储更新
- postgresql - Delphi7、Zeos DB 和 Postgres
- jquery - 未捕获的 TypeError:在 AJAX 调用中将循环结构转换为 JSON
- python - SQLAlchemy 的问题 - 推断外键的棉花糖嵌套对象