我有一张桌子,其中包括日期,时间,地点,文字。
现在它将报告当前年份和月份。
我正在尝试创建3个按钮,这些按钮将从数据库创建报告。
但问题是,当我点击上个月或下个月时,它只报告当月的上个月和下个月。所以我正在寻找某种跟踪日期。
示例:
3月(当前) - >(按下月按钮)= 4月 - > (按下月按钮)= May ...等
三月(当前) - >(按上一个月按钮)=二月 - > (按上个月按钮)= 1月
+ if is pressed next month when is DECEMBER 2013 reported then it must be new YEAR with january
+ same condition when backwards (January 2014 ->(previous button) = december 2013)
任何想法怎么做?
SELECT hlavni.datum_expirace, hlavni.priloha, hlavni.nazev, vedle.misto
FROM hlavni
INNER JOIN vedle ON hlavni.sekce = vedle.idecko WHERE vedle.idecko IN ( 6, 7, 8, 15, 14,
16, 17 ) AND YEAR( datum_expirace ) = YEAR( CURDATE( ) ) AND MONTH(datum_expirace) =
MONTH( CURDATE( ) ) ORDER BY `hlavni`.`datum_expirace` ASC, `hlavni`.`priloha` ASC");
答案 0 :(得分:0)
请查看以下登录信息:您可以尝试修改: 您可以将它用作推荐:
take one hidden field store in it current date:
<input type="hidden" name="date" value="<?php echo date('Y-m-01'); ?>" />
If you click On any of your three option pass type of it at submit time.
Now when you submit for Next,Previous,Current Month you need to check:
if ($_POST['type'] == 'previous')
{
$date = date('Y-m-d', strtotime("-1 month", strtotime($_POST['date'])));
} else if ($_POST['type'] == 'next') {
$date = date('Y-m-d', strtotime("+1 month", strtotime($_POST['date'])));
} else {
$date = $_POST['date'];
}
$start_date = date('Y-m-d', strtotime("-1 year", strtotime('+1 month', strtotime($date))));
$end_date = date('Y-m-01', strtotime($date));
$end_date = date('Y-m-d', strtotime('-1 second', strtotime('+1 month', strtotime($matrix_e_date_no))));
$loop_start_date = strtotime($start_date);
$loop_end_date = strtotime($end_date);
while ($loop_start_date < $loop_end_date) {
//Print your html content here
$loop_start_date = strtotime(date('Y-m-d', strtotime('+1 month', $loop_start_date)));
}
$set_date_again_in_hidden_field = date('Y-m-01', strtotime($date));
答案 1 :(得分:0)
您可以使用以下内容 假设日期格式为yyyy-mm-dd
上个月 SELECT * FROM表WHERE MONTH(date_created)= MONTH(date_created - INTERVAL 1 MONTH)
下个月 SELECT * FROM表WHERE MONTH(date_created)= MONTH(date_created + INTERVAL 1 MONTH)