在 PHP/MySQL 中按天分组记录 [英] Grouping records by day in PHP/MySQL

查看:45
本文介绍了在 PHP/MySQL 中按天分组记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个常见问题,我找不到一种优雅的方法来处理.

This is a common issue that I can't find an elegant way to handle.

数据库包含 5000 条记录.我需要在页面上显示这些记录,但需要按天对它们进行排序和分组.

Database contains 5000 records. I need to show these records on a page, but they need to be sorted and grouped by day.

记录3456

记录456

记录456

记录345234

记录3456

记录81

记录8324

记录983

记录834

记录918

...

等等.这如何在 MySQL/PHP 中完成?红宝石呢?我可以获取所有记录,然后对它们进行排序并使用 PHP 手动操作它们,但这很慢.

etc. How can this be done in MySQL/PHP? What about Ruby? I can grab all records and then sort them and manipulate them manually with PHP but that's SLOW.

推荐答案

做一个:

ORDER BY your_date_column

在查询中.您可能需要在 PHP 中进行分组 - 只需查看数据是否与最后一行不同,如果不同,则打印标题.

in the query. You'll probably have to do the grouping in PHP - just see if the data differs from the last row, if it does, print a header.

这篇关于在 PHP/MySQL 中按天分组记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆