如何将某一天选为 多变的

发布于 2024-10-29 16:46:27 字数 4494 浏览 0 评论 0原文

我正在使用下面的代码来显示日历。可以使用 href 单击这些日期。唯一的问题是我不知道如何获取链接中的日期变量。我可以得到月份和年份。不确定选择哪一天。

当前:

 <a href=/page.php?month=$month&year=$year>$i</a>

我需要:

 <a href=/page.php?month=$month&day=$day&year=$year>$i</a>

代码:

    <?php

    $day = $_GET["day"];
    $month = $_GET["month"];
    $year = $_GET["year"];
    $sel = $_GET["sel"];
    $what = $_GET["what"];

    $urlprt = $_SERVER['PHP_SELF'];
    $qstr = $_SERVER['QUERY_STRING'];
    $qss = explode('&',$qstr);
    $urllink = $urlprt."?".$qss[0];

    if($day == "")
    $day = date("j");
    if($month == "")
    $month = date("F");
    if($year == "")
    $year = date("Y");
    $currentTimeStamp = strtotime("$year-$month-$day");
    $monthName = date("F",$currentTimeStamp);
    $numDays = date("t", $currentTimeStamp);
    $counter = 0;
    $numEventsThisMonth = 0;
    $hasEvent = false;
    $todaysEvents = "";
    ?>
    <table align="center" style="border: 0px solid; width:420px; height:300px;">
    <tr>
    <td width='50' colspan='1'>
    <input type='button' value='< ' onClick='goLastMonth(<?php echo $month . ", 
    " . $year; ?>)'   style="border:0px; width:40px;">
   </td>
   <td width='250' colspan='5' align='center'>

   <span><?php echo "Month : ".$month . " &amp;
   Year : " . $year; ?></span><br>
   </td>
   <td width='50' colspan='1' align='right'>
          <input type='button' value=' > ' 
          onClick='goNextMonth(<?php echo $month . ", 
          " . $year; ?>)' style="border:0px; width:40px;">
           </td>
     </tr>
     <tr>
     <td class='head' width='30' style='background-color:#FFFFFF;'>S</td>
     <td class='head' width='30' style='background-color:#FFFFFF;'>M</td>
     <td class='head' width='30' style='background-color:#FFFFFF;'>T</td>
     <td class='head' width='30' style='background-color:#FFFFFF;'>W</td>
     <td class='head' width='30' style='background-color:#FFFFFF;'>T</td>
     <td class='head' width='30' style='background-color:#FFFFFF;'>F</td>
     <td class='head' width='30' style='background-color:#FFFFFF;'>S</td>
     </tr>
     <?php
     $numDays = date("t", $currentTimeStamp);
     for($i = 1; $i < $numDays+1; $i++, $counter++)
     {
    $timeStamp = strtotime("$year-$month-$i");
    if($i == 1)
    {
      // Workout when the first day of the month is
       $firstDay = date("w", $timeStamp);
   for($j = 0; $j < $firstDay; $j++, $counter++)
   {
   if($j==0)
   {
   echo "<td style='background-color:#FFFFFF;'>&nbsp;</td>";
   }
   else
   {
   echo "<td style='background-color:#FFFFFF;'>&nbsp;</td>";
   }
   }
   }
   if($counter % 7 == 0)
   {
   $counter=0;
   echo "</tr><tr>";
   if($i == date("d") && $month == date("F") && $year == date("Y"))
   {
   echo "<td width='30' style='background-color:#FFFFFF;'>
   <b><a id=caldates  href=/schedule.php?>$i</a></b></td>";
   }
   else
   {
   echo "<td width='30' style='background-color:#FFFFFF;'>
   <a id=caldates href=/schedule.php?>$i</a>  </td>";
   }
   }
   else
   {
   if($i == date("d") && $month == date("F") && $year == date("Y"))
   {
   echo "<td width='30' style='background-color:#FFFFFF;'><b><a id=caldates href=/schedule.php?>$i</a></b></td>";
   }
   else
   {
   echo "<td width='30' style='background-color:#FFFFFF;'>$i</td>";
   }
   }
   }
   ?>
   <?php
   $monthName = date("F", $currentTimeStamp);
   ?>
   </table>
   <script>
   <?php

   $month = date("F");

   ?>
   function goLastMonth(month, year)
   {
   // If the month is January, decrement the year
  if(month == 1)
  {
   --year;
  month = 13;
  }
  document.location.href = '<?php echo $urllink; ?>&month='+(month-1)+'&year='+year;
  }
  function goNextMonth(month, year)
   {
   // If the month is December, increment the year
   if(month == 12)
   {
   ++year;
  month = 0;
    }
     document.location.href = '<?php echo $urllink; ?>&month='+(month+1)+'&year='+year;
    }
                    </script>

I am using the code below to show a calendar. The days are clickable using a href. The only problem is i don't know how to get the day variable in the link. I can get the month and year. NOt sure what do pick as the day.

current:

 <a href=/page.php?month=$month&year=$year>$i</a>

I need:

 <a href=/page.php?month=$month&day=$day&year=$year>$i</a>

code:

    <?php

    $day = $_GET["day"];
    $month = $_GET["month"];
    $year = $_GET["year"];
    $sel = $_GET["sel"];
    $what = $_GET["what"];

    $urlprt = $_SERVER['PHP_SELF'];
    $qstr = $_SERVER['QUERY_STRING'];
    $qss = explode('&',$qstr);
    $urllink = $urlprt."?".$qss[0];

    if($day == "")
    $day = date("j");
    if($month == "")
    $month = date("F");
    if($year == "")
    $year = date("Y");
    $currentTimeStamp = strtotime("$year-$month-$day");
    $monthName = date("F",$currentTimeStamp);
    $numDays = date("t", $currentTimeStamp);
    $counter = 0;
    $numEventsThisMonth = 0;
    $hasEvent = false;
    $todaysEvents = "";
    ?>
    <table align="center" style="border: 0px solid; width:420px; height:300px;">
    <tr>
    <td width='50' colspan='1'>
    <input type='button' value='< ' onClick='goLastMonth(<?php echo $month . ", 
    " . $year; ?>)'   style="border:0px; width:40px;">
   </td>
   <td width='250' colspan='5' align='center'>

   <span><?php echo "Month : ".$month . " &
   Year : " . $year; ?></span><br>
   </td>
   <td width='50' colspan='1' align='right'>
          <input type='button' value=' > ' 
          onClick='goNextMonth(<?php echo $month . ", 
          " . $year; ?>)' style="border:0px; width:40px;">
           </td>
     </tr>
     <tr>
     <td class='head' width='30' style='background-color:#FFFFFF;'>S</td>
     <td class='head' width='30' style='background-color:#FFFFFF;'>M</td>
     <td class='head' width='30' style='background-color:#FFFFFF;'>T</td>
     <td class='head' width='30' style='background-color:#FFFFFF;'>W</td>
     <td class='head' width='30' style='background-color:#FFFFFF;'>T</td>
     <td class='head' width='30' style='background-color:#FFFFFF;'>F</td>
     <td class='head' width='30' style='background-color:#FFFFFF;'>S</td>
     </tr>
     <?php
     $numDays = date("t", $currentTimeStamp);
     for($i = 1; $i < $numDays+1; $i++, $counter++)
     {
    $timeStamp = strtotime("$year-$month-$i");
    if($i == 1)
    {
      // Workout when the first day of the month is
       $firstDay = date("w", $timeStamp);
   for($j = 0; $j < $firstDay; $j++, $counter++)
   {
   if($j==0)
   {
   echo "<td style='background-color:#FFFFFF;'> </td>";
   }
   else
   {
   echo "<td style='background-color:#FFFFFF;'> </td>";
   }
   }
   }
   if($counter % 7 == 0)
   {
   $counter=0;
   echo "</tr><tr>";
   if($i == date("d") && $month == date("F") && $year == date("Y"))
   {
   echo "<td width='30' style='background-color:#FFFFFF;'>
   <b><a id=caldates  href=/schedule.php?>$i</a></b></td>";
   }
   else
   {
   echo "<td width='30' style='background-color:#FFFFFF;'>
   <a id=caldates href=/schedule.php?>$i</a>  </td>";
   }
   }
   else
   {
   if($i == date("d") && $month == date("F") && $year == date("Y"))
   {
   echo "<td width='30' style='background-color:#FFFFFF;'><b><a id=caldates href=/schedule.php?>$i</a></b></td>";
   }
   else
   {
   echo "<td width='30' style='background-color:#FFFFFF;'>$i</td>";
   }
   }
   }
   ?>
   <?php
   $monthName = date("F", $currentTimeStamp);
   ?>
   </table>
   <script>
   <?php

   $month = date("F");

   ?>
   function goLastMonth(month, year)
   {
   // If the month is January, decrement the year
  if(month == 1)
  {
   --year;
  month = 13;
  }
  document.location.href = '<?php echo $urllink; ?>&month='+(month-1)+'&year='+year;
  }
  function goNextMonth(month, year)
   {
   // If the month is December, increment the year
   if(month == 12)
   {
   ++year;
  month = 0;
    }
     document.location.href = '<?php echo $urllink; ?>&month='+(month+1)+'&year='+year;
    }
                    </script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

穿越时光隧道 2024-11-05 16:46:27

我是否误解了这个问题,或者这一天很明显是$i

Did I misunderstood the question or is it obvious the day is $i?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文