<?php
$con=mysqli_connect("localhost","*********","***********","loadtracker");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT Date FROM pallettracker GROUP BY Date");
$DateList = mysqli_fetch_array($result);
$ListOfMonths=array('Dec','Nov','Oct','Sep','Aug','Jul','Jun','May','Apr','Mar','Feb','Jan');$ListOfDays = array('31','30','29','28','27','26','25','24','23','22','21','20','19','18','17','16','15','14','13','12','11','10','9','8','7','6','5','4','3','2','1');
foreach ($ListOfDays as $value) {
foreach ($ListOfMonths as $value2) {
$Yaer = array("'$value2' + '$value' + ',2013'");
foreach ($Yaer as $yaerdate) {
foreach ($DateList as $Dates) {
if ($yaerdate == $Dates)
{
echo $yaerdate;
echo '/';
}
}
}
}
}
?>
尝试订购2013年1月28日和Decending的日期数组。然后用/中间显示它们。对于Android应用程序
答案 0 :(得分:0)
您可以让SQL查询为您排序。假设该列是Date格式。如果没有,请查看:SQL ORDER BY date problem。
在查询中进行排序后,您只需将其转换为时间,然后根据需要格式化日期。这可能会给你你想要的东西:
<?
$datetime = strtotime($row->createdate);
$mysqldate = date("m/d/y g:i A", $datetime);
$result = mysqli_query($con,"SELECT Date FROM pallettracker GROUP BY Date");
foreach($result as $date){
$datetime = strtotime($result);
$date = date("M d, y", $datetime);
echo $date . '/';
}
?>
答案 1 :(得分:0)
我不明白,为什么在不使用分组功能时使用GROUP BY。 更好的方法是DISTINCT
我会以这种方式更新你的代码:
$result = mysqli_query($con,"SELECT DISTINCT `Date` FROM `pallettracker` ORDER BY `Date` DESC");
while($date = mysqli_fetch_assoc($result)
{
echo date('',strtotime($date['Date'])).'<br />';
}
重要的是,mysql中的“Date”col的格式为Date或Datetime