如何按数据库中的先前日期排序?
问题描述:
我想问的是如何从数据库记录中选择,并且我的php代码能够按日期对以前的日期进行排序,这就是我想在界面中显示的内容:
What I want to ask is how to select from database record and my php code able to sort previous date by date,which is what i want to display in my interface:
2011-10-01
2011-10-01
2011-10-01
something here..
2011-10-02
2011-10-02
something here..
2011-10-03
something here..
在我的数据库中,某些以前的日期有很多重复的日期,而有些只是一条记录,因此我需要对其进行排序以使界面更清晰
in my database some previous date got a lot duplicate date and some are only one record, so I need to sort it for make my interface more clear
这是我的代码(但不起作用):
here is my code(but it's not work):
$Current = date("Y-m-d" ,strtotime("now"));
$query= mysql_query("SELECT date FROM staff WHERE date < '$Current'");
while($res=mysql_fetch_array($query)){
echo $res['date'];
echo "something here";
}
谢谢
答
您不能简单地使用它吗?
Can't you simply use this?
SELECT `date` FROM staff WHERE `date` < NOW() ORDER BY `date`
或(如果您只需要不同的日期)
or (if you need only different dates)
SELECT DISTINCT `date` FROM staff WHERE `date` < NOW() ORDER BY `date`