的設定所以我花了一整天寫這個頁面拉存儲在表中特定組會議,日曆列表,改變個月
放棄任何會議,年齡超過4個月,並進一步在未來的比10個月,所以它顯示了一年的會議價值,但從3個月前開始,所以你可以看到最近發生的事情,如果你想除了會發生什麼。
一切正常 - 除了天+/-日期接縫非常字面 比較,我今天跑了測試27日和會議我在DB 28日和30日現身在一月
我可以將日期舍入到當前月份的第一個月份嗎?
有沒有更簡單的方法來寫這段代碼?
PHP代碼:
// post variables
$ScoutID=$_POST['ScoutID'];
$Rank=$_POST['Rank'];
$DenID=$_POST['DenID'];
// Define Dates
$Date = date("Y-m-d");
$Month1 = date("Y-m-d", strtotime("-3 months"));
$Month2 = date("Y-m-d", strtotime("-2 months"));
$Month3 = date("Y-m-d", strtotime("-1 months"));
$Month4 = $Date;
$Month5 = date("Y-m-d", strtotime("+1 months"));
$Month6 = date("Y-m-d", strtotime("+2 months"));
$Month7 = date("Y-m-d", strtotime("+3 months"));
$Month8 = date("Y-m-d", strtotime("+4 months"));
$Month9 = date("Y-m-d", strtotime("+5 months"));
$Month10 = date("Y-m-d", strtotime("+6 months"));
$Month11 = date("Y-m-d", strtotime("+7 months"));
$Month12 = date("Y-m-d", strtotime("+8 months"));
$Month12 = date("Y-m-d", strtotime("+9 months"));
//counter variables to print the month header
$M1=0;
$M2=0;
$M3=0;
$M4=0;
$M5=0;
$M6=0;
$M7=0;
$M8=0;
$M9=0;
$M10=0;
$M12=0;
$M12=0;
//Find Den Number from Den ID
$resultb = mysql_query('SELECT Den FROM Dens WHERE DenID = "'.$DenID.'"');
if (!resultb)
{
die('Could not query:' .mysql_error());
}
$DenNum = mysql_result($resultb,0);
$query = 'SELECT * FROM DenMeetings WHERE DenID = "'.$DenID.'" ORDER BY Date';
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
if($row['Date'] > $Month1 && $row['Date'] < $Month2)
{
if($M1 < 1)
{
echo '<h2>';
echo strftime('%B',strtotime($Month2));
echo '</h2>';
echo $row['Date'];
echo ' - 1 - ';
echo $row['Notes'];
echo '<br>';
$M1++;
}
else
{
echo $row['Date'];
echo ' - 1 - ';
echo $row['Notes'];
echo '<br>';
}
}
else if($row['Date'] > $Month2 && $row['Date'] < $Month3)
{
if($M2 < 1)
{
echo '<h2>';
echo strftime('%B',strtotime($Month3));
echo '</h2>';
echo $row['Date'];
echo ' - 2 - ';
echo $row['Notes'];
echo '<br>';
$M2++;
}
else
{
echo $row['Date'];
echo ' - 2 - ';
echo $row['Notes'];
echo '<br>';
}
}
else if($row['Date'] > $Month3 && $row['Date'] < $Month4)
{
if($M3 < 1)
{
echo '<h2>';
echo strftime('%B',strtotime($Month4));
echo '</h2>';
echo $row['Date'];
echo ' - 3 - ';
echo $row['Notes'];
echo '<br>';
$M3++;
}
else
{
echo $row['Date'];
echo ' - 3 - ';
echo $row['Notes'];
echo '<br>';
}
}
else if($row['Date'] > $Month4 && $row['Date'] < $Month5)
{
if($M4 < 1)
{
echo '<h2>';
echo strftime('%B',strtotime($Month5));
echo '</h2>';
echo $row['Date'];
echo ' - 1 - ';
echo $row['Notes'];
echo '<br>';
$M4++;
}
else
{
echo $row['Date'];
echo ' - 1 - ';
echo $row['Notes'];
echo '<br>';
}
}
else if($row['Date'] > $Month5 && $row['Date'] < $Month6)
{
if($M5 < 1)
{
echo '<h2>';
echo strftime('%B',strtotime($Month6));
echo '</h2>';
echo $row['Date'];
echo ' - 1 - ';
echo $row['Notes'];
echo '<br>';
$M5++;
}
else
{
echo $row['Date'];
echo ' - 1 - ';
echo $row['Notes'];
echo '<br>';
}
}
else if($row['Date'] > $Month6 && $row['Date'] < $Month7)
{
if($M6 < 1)
{
echo '<h2>';
echo strftime('%B',strtotime($Month7));
echo '</h2>';
echo $row['Date'];
echo ' - 1 - ';
echo $row['Notes'];
echo '<br>';
$M6++;
}
else
{
echo $row['Date'];
echo ' - 1 - ';
echo $row['Notes'];
echo '<br>';
}
}
else if($row['Date'] > $Month7 && $row['Date'] < $Month8)
{
if($M7 < 1)
{
echo '<h2>';
echo strftime('%B',strtotime($Month8));
echo '</h2>';
echo $row['Date'];
echo ' - 1 - ';
echo $row['Notes'];
echo '<br>';
$M7++;
}
else
{
echo $row['Date'];
echo ' - 1 - ';
echo $row['Notes'];
echo '<br>';
}
}
else if($row['Date'] > $Month8 && $row['Date'] < $Month9)
{
if($M8 < 1)
{
echo '<h2>';
echo strftime('%B',strtotime($Month9));
echo '</h2>';
echo $row['Date'];
echo ' - 1 - ';
echo $row['Notes'];
echo '<br>';
$M8++;
}
else
{
echo $row['Date'];
echo ' - 1 - ';
echo $row['Notes'];
echo '<br>';
}
}
else if($row['Date'] > $Month9 && $row['Date'] < $Month10)
{
if($M9 < 1)
{
echo '<h2>';
echo strftime('%B',strtotime($Month10));
echo '</h2>';
echo $row['Date'];
echo ' - 1 - ';
echo $row['Notes'];
echo '<br>';
$M9++;
}
else
{
echo $row['Date'];
echo ' - 1 - ';
echo $row['Notes'];
echo '<br>';
}
}
else if($row['Date'] > $Month10 && $row['Date'] < $Month11)
{
if($M10 < 1)
{
echo '<h2>';
echo strftime('%B',strtotime($Month11));
echo '</h2>';
echo $row['Date'];
echo ' - 1 - ';
echo $row['Notes'];
echo '<br>';
$M10++;
}
else
{
echo $row['Date'];
echo ' - 1 - ';
echo $row['Notes'];
echo '<br>';
}
}
else if($row['Date'] > $Month11 && $row['Date'] < $Month12)
{
if($M11 < 1)
{
echo '<h2>';
echo strftime('%B',strtotime($Month12));
echo '</h2>';
echo $row['Date'];
echo ' - 1 - ';
echo $row['Notes'];
echo '<br>';
$M11++;
}
else
{
echo $row['Date'];
echo ' - 1 - ';
echo $row['Notes'];
echo '<br>';
}
}
else if($row['Date'] > $Month12 && $row['Date'] < $Month13)
{
if($M12 < 1)
{
echo '<h2>';
echo strftime('%B',strtotime($Month11));
echo '</h2>';
echo $row['Date'];
echo ' - 1 - ';
echo $row['Notes'];
echo '<br>';
$M12++;
}
else
{
echo $row['Date'];
echo ' - 1 - ';
echo $row['Notes'];
echo '<br>';
}
}
else
{
}
}
輸出 - 注意的具體日期,1月:
月
2011-11-26 - 2 - 1個月
月
2011-1 2-15 - 3 -
2011-12-20 - 3 - test32
2011-12-24 - 3 - 測試
2011-12-26 - 3 - 今天
一月
** 2011-12-28 - 1 - 測試
2011-12-30 - 1 - 試驗**
2012-01-05 - 1 - test23
2012-01-13 - 1 - 12
2012-01-13 - 1 - 12
2012-01-13 - 1 - 12
2012-01 -20 - 1 - 32w45
月
2012-04-26 - 1 - 4個月
2012-04-26 - 1 - +4個月
必須有* *了以一種更好的方式來做到這一點 - 我敢打賭,它與一個'for'循環開始。 – Ben 2011-12-28 02:09:26
它與[數組](http://www.php.net/manual/en/language.types.array.php)以及 – 2011-12-28 02:20:48
我得到四捨五入的部分..... – PHPFouts 2011-12-28 02:31:41