我正在构建一个网站(我的第一个!),它列出了事件,必要时嵌套在年和月的标题中。我知道这有点乱,但是嘿!
我在某处犯了一个错误,并且 MySQL 数据库中的日期字段未正确传递。所以它只是默认为 01-01-1970
<?php
$query = 'SELECT * FROM events';
$result = mysql_query( $query );
$current_month = 'no_month_given';
$current_year = 'no_year_given';
$year_count = 0;
$month_count = 0;
$year = date("Y", strtotime($row['event_startdate']));
$month = date("M", strtotime($row['event_startdate']));
$startday = date("d", strtotime($row['event_startdate']));
$endday = date("d", strtotime($row['event_enddate']));
while($row = mysql_fetch_array($result))
{
/* YEAR */
if($current_year != $year)
{
$current_year = $year;
echo " <div id=\"year\">
<p class=\"vert\">" .$current_year. "</p>";
$year_count++;
}
/* MONTH */
if($current_month != $month)
{
$current_month = $month;
echo '<div id="month"><h1>' . $current_month . '</h1>';
$month_count++;
}
/* EVENT DETAILS */
}