dongpu1331 2014-08-04 08:19
浏览 10
已采纳

php日历上一个按钮不断递增

"Thank you I have already solved my problem I think this one work"

I have a code that display only mondays of the month.

The next button is not calculating well.

Supposed to be it well end on 12(Month).

But it continuously adding the month.

This is my PHP code.

<?php


$current_month = date("n");
$month = ($_GET['m']) ? $_GET['m'] : date("n");


$previous_month = ($month - 1);

$next_month = ($month + 1);

$year = ($_GET['y']) ? $_GET['y'] : date("Y");
$previous_year = $year;

if($month == 0)
{
  $month = 12;
  $year--;
}

if($month == 13)
{
  $month = 1;
  $year++;
}

if($previous_month == 0)
{
  $previous_month = 12;
  $previous_year--;
}

$startDate  = $year."-".$month."-01";
$endDate = $year."-".$month."-31";



$endDate = strtotime($endDate);
echo("<form name = 'formCalendar' id = 'formCalendar' action = 'calendar1.php?' method = 'get'>");
echo '<table border=1>';
echo '<tr>';
for($i = strtotime('Monday', strtotime($startDate)); $i <= $endDate; $i = strtotime('+1 week', $i))

    echo '<td>'.date('d-M-y', $i).'</td>';   

echo '</tr>';   
echo("        </select>");
echo("        <input type = 'button' name = 'prev' value = '<<' onclick = 'location=\"calendar1.php?m={$previous_month}&y={$previous_year}\"'/>");
echo("        <input type = 'button' name = 'next' value = '>>' onclick = 'location=\"calendar1.php?m=". ($month + 1)."&y={$year}\"'/>");
echo("  </table>");
echo("<form>");

?>

Pls help fix the problem.

  • 写回答

3条回答 默认 最新

  • dongpu5600 2014-08-04 08:40
    关注

    here is your complete working code

    <?php
    $current_month = date("n");
    
    $month = (isset($_GET['m'])) ? $_GET['m'] : date("n");
    $year = (isset($_GET['y'])) ? $_GET['y'] : date("Y");
    
    $previous_month = ($month - 1);
    $next_month = ($month + 1);
    
    $previous_year = $year;
    $next_year = $year;
    
    if($previous_month==0)
    {
        $previous_month = 12;
        $previous_year = $year-1;
    }
    
    if($next_month>12)
    {
        $next_month = 1;
        $next_year = $year+1;
    }
    
    $startDate  = $year."-".$month."-01";
    $endDate = $year."-".$month."-31";        
    
    $endDate = strtotime($endDate);
    echo("<form name = 'formCalendar' id = 'formCalendar' action = 'calender1.php?' method = 'get'>");
    echo '<table border=1>';
    echo '<tr>';
    for($i = strtotime('Monday', strtotime($startDate)); $i <= $endDate; $i = strtotime('+1 week', $i))
    
        echo '<td>'.date('d-M-y', $i).'</td>';   
    
    echo '</tr>';   
    echo("        </select>");
    echo("        <input type = 'button' name = 'prev' value = '<<' onclick = 'location=\"calender1.php?m={$previous_month}&y={$previous_year}\"'/>");
    echo("        <input type = 'button' name = 'next' value = '>>' onclick = 'location=\"calender1.php?m={$next_month}&y={$next_year}\"'/>");
    echo("  </table>");
    echo("<form>");
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站