php 和 mysql 按年份和日期获取数据!表结构?
在制作示例详细信息页面时,我遇到了一个非常令人困惑的情况。我真正想做的是这样的:
+----------------------------------------------------+
+ Year | Month | Date | Total Gain +
+----------------------------------------------------+
+ 2003 | January | 26/01/2003 | +90 % +
+ 2003 | January | 27/01/2003 | +10 % +
+ 2003 | Feburary| 01/02/2003 | -29 % +
+ 2003 | Feburary| 15/02/2003 | +0.52 % +
+----------------------------------------------------+
我真正想要的是我可以列出月份名称和年份,例如 mysql_query('SELECT Month FROM mytable WHEREyear="2003"');
但是问题是它显示一月两次。我想显示一月一次,并在其旁边显示一个链接,该链接将转到下一页。这将显示一月份的统计数据。
While making a sample details page, I just stuck upon a really confusing situation. What i actually want to do is like this:
+----------------------------------------------------+
+ Year | Month | Date | Total Gain +
+----------------------------------------------------+
+ 2003 | January | 26/01/2003 | +90 % +
+ 2003 | January | 27/01/2003 | +10 % +
+ 2003 | Feburary| 01/02/2003 | -29 % +
+ 2003 | Feburary| 15/02/2003 | +0.52 % +
+----------------------------------------------------+
What I actually want is that I can list the Month names and year wise like mysql_query('SELECT month FROM mytable WHERE year="2003"');
But the problem is it shows January two time. I want to display January one time and a link next to it which will carry to the next page. This will show the stats of January.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您应该使用
GROUP BY
子句并计算您的总增益。(由于没有指定表结构,所以这里就猜测一下)
Maybe you should use a
GROUP BY
clause and calculates your Total gain as well.(Since the table structure is not specified, I'll guess here)
我认为您正在寻找的是
DISTINCT
查询,即I think what youre looking for is
DISTINCT
query, ie