- UID
- 4225
- 帖子
- 108
- 积分
- 7471
- 阅读权限
- 60
- 注册时间
- 2005-8-24
- 最后登录
- 2015-3-28
- 在线时间
- 1597 小时
|
前两天在8达看到有人说学好PHP可以当高帅富,钓丝学了两天,编了个日历。但是点上月下月不会变化啊,特来跪求木天使指导一下。- //calendar.inc文件
- <?php
- function create_calendar($tm)
- {
- $year = date('Y', $tm);
- $month = date('n', $tm);
- $day = date('d', $tm);
- $week = date('w', mktime(0, 0, 0, $month, 1, $year));
- $days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
- $day_num = "";
- $count = 0;
- $head = array("日", "一", "二", "三", "四", "五", "六");
- echo "<table class='calendar'>";
- echo "<thead>";
- echo "<tr>";
- echo "<th class='head'><a href='#'><</a></th>";
- echo "<th colspan='5' class='head'>".date('Y年m月', $tm)."</th>";
- echo "<th class='head'><a href='#'>></a></th>";
- echo "</tr>";
- echo "<tr>";
- foreach($head as $h)
- {
- echo "<th>$h</th>";
- }
- echo "</tr>";
- echo "</thead>";
- echo "<tbody>";
- for($i = 0; $i < 6; $i++)
- {
- echo "<tr>";
- for($j = 0; $j < 7; $j++)
- {
- if(($j >= $week || $i > 0) && $count < $days)
- {
- $day_num = ++$count;
- if($count == $day)
- echo "<td class='celltoday'>".$day_num."</td>";
- else
- echo "<td class='cellday'>".$day_num."</td>";
- }
- else
- {
- $day_num = "";
- echo "<td class='cell'>".$day_num."</td>";
- }
- }
- echo "</tr>";
- }
- echo "</tbody>";
- echo "</table>";
- }
- ?>
- //html文件
- <!DOCTYPE HTML>
- <?php
- include("calendar.inc");
- ?>
- <html>
- <head>
- <title>My Calendar Test</title>
- <link rel="stylesheet" type="text/css" href="calendar.css" />
- </head>
- <body>
- <?php
- for($i = 1; $i <= 12; $i++)
- {
- echo "<div style='float: left; margin: 10px 10px;'>";
- create_calendar(mktime(0,0,0,$i,21,2012));
- echo "</div>";
- if($i % 4 == 0)
- echo "<div style='clear: both;'>";
- }
- ?>
- </body>
- </html>
- //CSS文件
- table.calendar {
- font-family: arial;
- font-size: 12px;
- font-weight: normal;
- /*border: 1px solid gray;*/
- border-spacing: 1px 1px;
- background: aliceblue;
- }
- th.head {
- background-color: greenyellow;
- text-align: center;
- }
- td.cellday {
- width: 19px;
- height: 15px;
- background-color: #bbccdd;
- text-align: center;
- text-decoration: underline;
- /*border: 1px solid gray;*/
- color: white;
- cursor: pointer;
- }
- td.celltoday {
- width: 19px;
- height: 15px;
- background-color: orange;
- text-align: center;
- text-decoration: underline;
- /*border: 1px solid gray;*/
- color: white;
- cursor: pointer;
- }
- td.cell {
- width: 19px;
- height: 15px;
- background-color: #bbccdd;
- text-align: center;
- text-decoration: underline;
- /*border: 1px solid gray;*/
- }
复制代码 |
|