PHP MySQL 按日和月排序

发布于 2024-09-12 13:56:40 字数 276 浏览 5 评论 0原文

$query = mysql_query('SELECT * from rbf_edades_news order by month DESC '.$limit.'');

月和日在不同的字段,

任何想法,这可能吗?

$query = mysql_query('SELECT * from rbf_edades_news order by month and DESC '.$limit.'');

谢谢!

$query = mysql_query('SELECT * from rbf_edades_news order by month DESC '.$limit.'');

month and day are in different fields,

Any idea, is this possible?

$query = mysql_query('SELECT * from rbf_edades_news order by month and DESC '.$limit.'');

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

迎风吟唱 2024-09-19 13:56:40

这将首先按月排序,然后按天排序:

$query = mysql_query('SELECT * from rbf_edades_news order by month DESC, day DESC '.$limit.'');

This will sort first by month and then by day:

$query = mysql_query('SELECT * from rbf_edades_news order by month DESC, day DESC '.$limit.'');
花开柳相依 2024-09-19 13:56:40

您可以按 2 列排序,例如

$query = mysql_query('SELECT * from rbf_edades_news order by month DESC, day  DESC '.$limit.'');

you can order by 2 columns like

$query = mysql_query('SELECT * from rbf_edades_news order by month DESC, day  DESC '.$limit.'');
傲性难收 2024-09-19 13:56:40

您可以将 order by 与 2 个字段一起使用。这应该有效:

$query = mysql_query('SELECT * from rbf_edades_news order by month, day DESC '.$limit.'');

You can use order by with 2 field. This should work:

$query = mysql_query('SELECT * from rbf_edades_news order by month, day DESC '.$limit.'');
千柳 2024-09-19 13:56:40

不,您的第二个查询不可能。 DESC 必须位于字段名称旁边,如第一个示例中所示,它用于按月份降序排列结果。使用 ASC 进行升序排列。

如果想按天和月排序,可以这样做:

SELECT * from rbf_edades_news order by day DESC, month DESC

一个问题,$limit变量的内容到底是什么?

No, your second query is not possible. DESC has to be next to a fieldname like in your first example and it is used to order your results by month in descending order. Use ASC for ascending order.

If you want to order by day and month, you can do the following:

SELECT * from rbf_edades_news order by day DESC, month DESC

One question, what is exactly the content of the $limit variable?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文