设为首页收藏本站

八达网

 找回密码
 注册
查看: 402|回复: 4
打印 上一主题 下一主题

前两天在8达看到有人说学好PHP可以当高帅富,钓丝学了两天,编了个日历。但是点上月下

[复制链接]

2

主题

0

好友

7471

积分

大象

跳转到指定楼层
1
发表于 2012-9-23 20:11 |只看该作者 |倒序浏览
前两天在8达看到有人说学好PHP可以当高帅富,钓丝学了两天,编了个日历。但是点上月下月不会变化啊,特来跪求木天使指导一下。
  1. //calendar.inc文件
  2. <?php
  3. function create_calendar($tm)
  4. {
  5.         $year = date('Y', $tm);
  6.         $month = date('n', $tm);
  7.         $day = date('d', $tm);
  8.         $week = date('w', mktime(0, 0, 0, $month, 1, $year));
  9.         $days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
  10.         $day_num = "";
  11.         $count = 0;
  12.         $head = array("日", "一", "二", "三", "四", "五", "六");

  13.         echo "<table class='calendar'>";
  14.         echo "<thead>";
  15.         echo "<tr>";
  16.         echo "<th class='head'><a href='#'><</a></th>";
  17.         echo "<th colspan='5' class='head'>".date('Y年m月', $tm)."</th>";
  18.         echo "<th class='head'><a href='#'>></a></th>";
  19.         echo "</tr>";

  20.         echo "<tr>";
  21.         foreach($head as $h)
  22.         {
  23.                 echo "<th>$h</th>";
  24.         }
  25.         echo "</tr>";

  26.         echo "</thead>";
  27.         echo "<tbody>";
  28.         for($i = 0; $i < 6; $i++)
  29.         {
  30.                 echo "<tr>";
  31.                 for($j = 0; $j < 7; $j++)
  32.                 {
  33.                         if(($j >= $week || $i > 0) && $count < $days)
  34.                         {
  35.                                 $day_num = ++$count;
  36.                                 if($count == $day)
  37.                                         echo "<td class='celltoday'>".$day_num."</td>";
  38.                                 else
  39.                                         echo "<td class='cellday'>".$day_num."</td>";
  40.                         }
  41.                         else
  42.                         {
  43.                                 $day_num = "";
  44.                                 echo "<td class='cell'>".$day_num."</td>";
  45.                         }
  46.                 }
  47.                 echo "</tr>";
  48.         }
  49.         echo "</tbody>";
  50.         echo "</table>";
  51. }

  52. ?>

  53. //html文件

  54. <!DOCTYPE HTML>
  55. <?php
  56. include("calendar.inc");
  57. ?>
  58. <html>
  59. <head>
  60. <title>My Calendar Test</title>
  61. <link rel="stylesheet" type="text/css" href="calendar.css" />
  62. </head>
  63. <body>
  64. <?php
  65. for($i = 1; $i <= 12; $i++)
  66. {
  67.         echo "<div style='float: left; margin: 10px 10px;'>";
  68.         create_calendar(mktime(0,0,0,$i,21,2012));
  69.         echo "</div>";
  70.         if($i % 4 == 0)
  71.                 echo "<div style='clear: both;'>";
  72. }
  73. ?>
  74. </body>
  75. </html>

  76. //CSS文件

  77. table.calendar {
  78.     font-family: arial;
  79.     font-size: 12px;
  80.     font-weight: normal;
  81.         /*border: 1px solid gray;*/
  82.         border-spacing: 1px 1px;
  83.         background: aliceblue;
  84. }

  85. th.head {
  86.         background-color: greenyellow;
  87.         text-align: center;
  88. }

  89. td.cellday {
  90.         width: 19px;
  91.         height: 15px;
  92.         background-color: #bbccdd;
  93.         text-align: center;
  94.         text-decoration: underline;
  95.         /*border: 1px solid gray;*/
  96.         color: white;
  97.         cursor: pointer;
  98. }

  99. td.celltoday {
  100.         width: 19px;
  101.         height: 15px;
  102.         background-color: orange;
  103.         text-align: center;
  104.         text-decoration: underline;
  105.         /*border: 1px solid gray;*/
  106.         color: white;
  107.         cursor: pointer;
  108. }

  109. td.cell {
  110.         width: 19px;
  111.         height: 15px;
  112.         background-color: #bbccdd;
  113.         text-align: center;
  114.         text-decoration: underline;
  115.         /*border: 1px solid gray;*/
  116. }
复制代码

5

主题

0

好友

2553

积分

坦克

2
发表于 2012-9-23 20:15 |只看该作者
天下码农皆屌丝~~~
回复

使用道具 举报

The.WK 该用户已被删除
3
发表于 2012-9-23 23:29 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

105

主题

0

好友

740

积分

龙骑士

4
发表于 2012-9-24 08:15 |只看该作者
我也想当高富帅。。。。
回复

使用道具 举报

头像被屏蔽

194

主题

1

好友

1万

积分

禁止发言

5
发表于 2012-9-24 08:18 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

手机版|Archiver|八达网    

GMT+8, 2025-11-25 01:51

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部