Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
列出使用PHP在mySQL数据库中找到的日期_Php_Mysql_Date - Fatal编程技术网

列出使用PHP在mySQL数据库中找到的日期

列出使用PHP在mySQL数据库中找到的日期,php,mysql,date,Php,Mysql,Date,假设这是我数据库中的表: ID | APP_TIME | NAME ---------------------------------------------------- 1 | 2012-07-08 10:00:00 | John 2 | 2012-07-08 12:00:00 | Johnny 3 | 2012-07-09 13:00:00 | Fred 4 |

假设这是我数据库中的表:

ID      | APP_TIME                  | NAME
----------------------------------------------------
1       | 2012-07-08 10:00:00       | John
2       | 2012-07-08 12:00:00       | Johnny
3       | 2012-07-09 13:00:00       | Fred
4       | 2012-07-10 09:00:00       | George
5       | 2012-07-10 10:30:00       | Eva
6       | 2012-07-10 14:00:00       | Monica
7       | 2012-07-11 12:00:00       | Helen
8       | 2012-07-11 13:00:00       | Kim
然后我希望在我的站点上输出的内容:

07-08-2012
Time    | Name
----------------------------------------------------
10:00   | John
12:00   | Johnny


07-09-2012
Time    | Name
----------------------------------------------------
13:00   | Fred


07-10-2012
Time    | Name
----------------------------------------------------
09:00   | George
10:30   | Eva
14:00   | Monica


07-11-2012
Time    | Name
----------------------------------------------------
12:00   | Helen
13:00   | Kim
我的问题是没有格式化日期时间值等等。。。 我面临的挑战是根据结果“属于”的日期列出结果


有人帮忙吗?:)

让MySQL像这样为您做艰苦的工作:

SELECT DATE(app_time) as `day`, TIME(app_time) as `time`, name FROM table ORDER BY `day` ASC, `time` ASC
这将返回日期、时间和名称,按日期和时间排序

然后将结果行循环并聚合到下面示例中所示的任何结构中(假设您已经从查询集中获得了一个结果集
$result
,并且您正在使用mysqli)


提出了以下解决方案:

$today = date('%Y-%m-%d 00:00:00');
$get_dates = mysql_query("SELECT DISTINCT DATE_FORMAT(app_time, '%Y-%m-%d') AS new_date FROM reservations WHERE app_time > '$today' ORDER BY app_time ASC");
while ($row = mysql_fetch_array($get_dates)) {
    $the_date = $row['new_date'];
    $results = mysql_query("SELECT * FROM reservations WHERE app_time >= '$the_date 00:00:00' AND app_time < '$the_date 23:59:59' ORDER BY app_time ASC");
    while ($the_results = mysql_fetch_array($results))
    {
    // Do some stuff eg:
    echo $the_results['name'] . '<br />';
    }
}
$today=日期(“%Y-%m-%d 00:00:00”);
$get_dates=mysql_查询(“选择不同的日期格式(应用程序时间,%Y-%m-%d))作为新的应用程序日期,其中应用程序时间>'$today'按应用程序时间ASC排序”);
while($row=mysql\u fetch\u数组($get\u日期)){
$the_date=$row['new_date'];
$results=mysql_query(“从预订中选择*,其中app_time>='$the_date 00:00:00'和app_time<'$the_date 23:59:59'按app_time ASC排序”);
while($theu results=mysql\u fetch\u数组($results))
{
//做一些事情,例如:
echo$u结果['name']。
; } }
跟踪临时变量中的日期。当处理的结果与上一个结果不同时,请关闭该表(或使用的任何结构),然后开始下一个表。
$today = date('%Y-%m-%d 00:00:00');
$get_dates = mysql_query("SELECT DISTINCT DATE_FORMAT(app_time, '%Y-%m-%d') AS new_date FROM reservations WHERE app_time > '$today' ORDER BY app_time ASC");
while ($row = mysql_fetch_array($get_dates)) {
    $the_date = $row['new_date'];
    $results = mysql_query("SELECT * FROM reservations WHERE app_time >= '$the_date 00:00:00' AND app_time < '$the_date 23:59:59' ORDER BY app_time ASC");
    while ($the_results = mysql_fetch_array($results))
    {
    // Do some stuff eg:
    echo $the_results['name'] . '<br />';
    }
}