doupo1865 2018-06-05 08:05
浏览 37
已采纳

基于php周的日历月初

Last question I want to add events from MySQL but I cant get the loops to get ok. They now loop the calendar 3 times and the enter image description heredates in calendar 30times. How can I get the while loop to loop 1 time? If that is not to big change in the code. look att the picture it explanins what is wrong.

  $sql = "SELECT DATE_FORMAT(date,'%d') AS dateformat FROM test";
    $result = mysqli_query($con, $sql);

     while($row=mysqli_fetch_array($result)){
    $week_number = 22;
    $year = 2018;

    $today = mktime(0, 0, 0, date("n"), date("d"), date("Y"));
    $curMonth = date("6", $today);
    $curDay = date("25", $today);


    for ($i = 1; $i <= 5; $i++) {

      echo "<tr>";
    for ($day = 1; $day <= 7; $day++) {

         $datetime = strtotime($year."W".$week_number.$day);
         $month = date('n', $datetime);
         $daysnumber = date('d', $datetime);

         $sqldate = $row['dateformat'];

          echo $sqldate ;


    if ($curMonth === $month && $daysnumber === $curDay) {
          echo"<td width=50 bgcolor='#f44242'>$daysnumber</td>";


          } elseif($curMonth === $month && $daysnumber == $sqldate) {

          echo"<td width=50 bgcolor='#1e8e8e'>$sqldate</td>";


          } elseif($curMonth === $month) {

          echo"<td width=50 bgcolor='#ffffff'>$daysnumber</td>";
        } else {

          echo"<td width=50 bgcolor='#ffffff'></td>";
        }
      }

          echo "</tr>";
    $week_number++;


}}
  • 写回答

1条回答 默认 最新

  • douwen2072 2018-06-05 08:31
    关注

    don't show number 03 because this code

    elseif ($daysnumber>=$today){
        echo"<td bgcolor='#ffffff'></td>" ;    
    }
    

    current value of $today=2 , $daysnumber=03

    I donot understand your request,

    <?
    $week_number = 22;
    $year = 2018;
    // mktime(0, 0, 0, date("m"), date("d") , date("Y"));
    $today = mktime(0, 0, 0, date("m"), '2', date("Y"));
    // 1 through 12
    $curMonth = date("n", $today);
    // 1 to 31
    $curDay = date("j", $today);
    // create table
    echo "<table border=1>";
    // showing 4 weekly week 22~
    for ($i = 1; $i <= 4; $i++) {
      echo "<tr>";
      for ($day = 1; $day <= 7; $day++) {
        $datetime = strtotime($year."W".$week_number.$day);
        // 1 to 31
        $month = date('n', $datetime);
        // 1 through 12
        $daysnumber = date('j', $datetime);
        var_dump($month . '/'. $daysnumber);
        if ($curMonth === $month && $daysnumber === $curDay) {
          echo"<td width=50 bgcolor='#f44242'>$daysnumber</td>";
        } elseif($curMonth === $month) {
          // other days
          echo"<td width=50 bgcolor='#8e8e8e'>$daysnumber</td>";
        } else {
          // other month
          echo"<td width=50 bgcolor='#ffffff'>$daysnumber</td>";
        }
      }
      echo "</tr>";
      $week_number++;
    }
    
    echo "</table>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序