我有这个简单的代码从我的mysql数据库中收集数据:
$get = mysql_query("SELECT * FROM table ORDER BY dato ASC") or die(mysql_error());
if(mysql_num_rows($get)) {
while($show = mysql_fetch_array($get)) {
}
} else {
echo "No results";
}
但是这个列表现在超过了200个项目,我想在日期上对它们进行排序,例如我已经做过了。
26/08-2015
1. line
2. line
3. line
4. line
27/08-2015
5. line
6. line
7. line
而不是
1. line
2. line
3. line
4. line
5. line
6. line
7. line
我现在得到了
我排序的日期是mktime日期。
$dato = mktime(0, 0, 0, date('m'), date('d'), date('y'));
答案 0 :(得分:1)
使用此
$currentDate = null;
$get = mysql_query("SELECT * FROM table ORDER BY dato ASC") or die(mysql_error());
if(mysql_num_rows($get)) {
while($show = mysql_fetch_array($get)) {
if($currentDate != $show['dato'])
echo "<BR><BR>";
$currentDate = $show['dato'];
}
} else {
echo "No results";
}
答案 1 :(得分:1)
使用此,
$get = mysql_query("SELECT DISTINCT(DATE(`date`)) as dt, t.* FROM table t ORDER BY 1") or die(mysql_error());
if(mysql_num_rows($get)) {
$prevDT = "";
while($show = mysql_fetch_array($get)) {
if (strlen($prevDT) < 0 || strcmp($prevDT, $show['dt']) != 0){
echo("<br />");
echo($show['dt']."<br />");
$prevDT = $show['dt'];
}
echo($show['field']."<br />");
}
} else {
echo "No results";
}