通过下拉列表对数据库条目进行排序
我很好奇是否有人可以帮助我,因为我在任何地方都找不到与它完全相关的任何东西,这让我发疯。
我想在页面上有一个下拉列表,这将使访问者可以选择按年份对所有条目进行排序。我有 2001 年、2005 年、2009 年、2010 年的条目。年份应显示在下拉列表中,因此访问者可以根据需要轻松选择 2001 年的所有条目。 每个条目的年份都位于我拥有的一个数据库表中。
换句话说,我只是想要一个“排序依据”下拉列表,您现在几乎可以在任何购物网站上看到它。但随着岁月的流逝。
预先感谢您的回复!
I'm curious if anyone could possibly help me, because I can't find anything exactly related to it anywhere, and it's driving me nuts.
I'd like to have a dropdown list on a page, that will give the visitor the option to sort all entries by year. I have entries from i.e. 2001, 2005, 2009, 2010. The years should be displayed in the dropdown, so the visitor can easily just select all entries dated 2001 if they want.
The year for each entry is located in the one database table I have.
In other words, I simply want a "sort by" dropdown that you can see on pretty much any shopping site nowadays. But with set years.
Thanks in advance for any replies!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,您创建一个下拉列表,进行查询,然后使用
ORDER BY
语法按特定字段对其进行排序。因此,按年份排序(从旧到新):
从新到旧
也许您说错了,意思是按年份过滤。在这种情况下,您将使用
WHERE
子句:这将使得仅包含 2010 年的帖子。
Well, you create a dropdown, make a query, and use the
ORDER BY
syntax to order it by a certain field.So, to sort it by year (Oldest to Newest):
Newest to Oldest
Perhaps you mispoke, and meant to say filter by the year. In that case you would use the
WHERE
clause:This would make it so that only posts with the year 2010 are included.