在PHP中创建调度系统[关闭]

mklgxw1f  于 2023-10-15  发布在  PHP
关注(0)|答案(1)|浏览(102)

已关闭此问题为not reproducible or was caused by typos。它目前不接受回答。

此问题是由打印错误或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这一个是解决的方式不太可能帮助未来的读者。
3天前关闭。
Improve this question
我正在建立一个工作日历调度系统,并被困在这里,在个别行的日期总是月数(12月12日,...),如果有人可以看到一些地方我犯了一个错误,请让我知道。

<?php
   
function build_calendar($month,$year){
  $daysOfWeek = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
  $firstDayOfMonth = mktime(0,0,0,$month,1,$year);
  $numberDays = date('t',$firstDayOfMonth);
  $dateComponents = getdate($firstDayOfMonth);
  $monthName = $dateComponents['month'];
  $dayOfWeek = $dateComponents['wday'];
  $datetoday = date('Y-m-d');
  $prev_month = date('m',mktime(0,0,0,$month-1,1,$year));
  $prev_year = date('Y',mktime(0,0,0,$month-1,1,$year));
  $next_month = date('m',mktime(0,0,0,$month+1,1,$year));
  $next_year = date('Y',mktime(0,0,0,$month+1,1,$year));
  $calendar = "<center><h2>$monthName $year</h2>";
  $calendar.= "<a class='btn btn-primary btn-xs' href='?month=".$prev_month."&year=".$prev_year."'>Prev Month</a> ";
  $calendar.= "<a class='btn btn-primary btn-xs' href='?month=".date('m')."&year=".date('Y')."'>Current Month</a> ";
  $calendar.= "<a class='btn btn-primary btn-xs' href='?month=".$next_month."&year=".$next_year."'>Next Month</a></center>";
  $calendar.="<br><table class='table table-bordered'>";
  $calendar.="<tr>";

  foreach($daysOfWeek as $day){
    $calendar.="<th class='header'>$day</th>";
  }
  $calendar.="</tr><tr>";
  $currentDay = 1;

  if($dayOfWeek > 0){
    for($i=0;$i<$dayOfWeek;$i++){
      $calendar.="<td class='empty'></td>";
    }
  }

工作直到这里.,这里是应该用日期数字填充表格的部分。

$month = str_pad($month,2,"0",STR_PAD_LEFT);

  while($currentDay<=$numberDays){

    if($dayOfWeek==7){
      $dayOfWeek = 0;
      $calendar.="</tr><tr>";
    }

    $currentDayRel = str_pad($month,2,"0",STR_PAD_LEFT);
    $date = "$year-$month-$currentDayRel";
    $dayName = strtolower(date('I', strtotime($date)));
    $today = $date==date('Y-m-d') ? 'today' : '';
    $calendar.="<td class='$today'><h3>$currentDayRel</h3></td>";
    $currentDay++;
    $dayOfWeek++;
  }
?>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
  
</head>

<body>
      <div class="container">
        <div class="row">
          <div class="col-md-12">
            <?php
              $dateComponents = getdate();
              if(isset($_GET['month'])&&isset($_GET['year'])){
                $month=$_GET['month'];
                $year=$_GET['year'];
              }
              else{
                $month=$dateComponents['mon'];
                $year=$dateComponents['year'];
              }
              echo build_calendar($month,$year);
            ?>
</body>
</html>
wz3gfoph

wz3gfoph1#

您应该输入$currentDay而不是Month。

$currentDayRel = str_pad($currentDay,2,"0",STR_PAD_LEFT);

相关问题