Home >Backend Development >PHP Tutorial >按照案例写的万年历怎么加载不了日期,求各位老师帮忙看下

按照案例写的万年历怎么加载不了日期,求各位老师帮忙看下

WBOY
WBOYOriginal
2016-06-23 09:15:071535browse

<html><head><meta http-equiv="content-type" content="text/html" charset="UTF-8"><body><style type="text/css"></style></head><?phpdate_default_timezone_set('PRC');if(isset($_GET['year'])){    $year=$_GET['year'];}else{    $year=date("Y");}if(isset($_GET['month'])){    $month=$_GET['month'];}else{    $month=date("m");}$date=01;//初始化月数据$day=01;//初始化日数据$off=0;//检测年数据是否正确if($year<0 or $year>9999){//如果年数据不正确,显示错误信息。关闭返回上一页    echo "<script> alert('年份应在1至9999之间');history.go(-1);</script>";    return false;}if($month<0 or $month >12){    //如果月数据不争取,显示错误提示,关闭返回上一页    echo "<script>alert('月份应在1至12之间');history.go(-1);</script>";    return false;}//检测数据是否争取,否则++;//while(checkdate($month,$day,$year)){  //$date++;//}//绘制万年历表头?><form method="get" name="calendar">    <table width="100%">        <tr align="center">            <td>                <input name="year" type="text" value=<?=$year?> >                <input name="month" type="text" value=<?=$month?> >                <input name="submit" type="submit"  value="跳转">            </td>        </tr>        </table>    <table width="100%">        <tr align="center">            <td bgcolor="#dc143c" width="10%">                日            </td>            <td width="100">                一            </td>            <td width="100">                二            </td>            <td width="100">                三            </td>            <td width="100">                四            </td>            <td width="100">                五            </td>            <td bgcolor="#dc143c" width="100">                六            </td>        </tr><tr>   <?php   //构造万年表   while($day<$date){       //设置日期颜色,如果是当前日期,使用红色进行标识       if($day==date('d')&&$year==date('Y')&&$month==date('m')){           $date_color="red";       }else{           $date_color="black";       }       //设置星期天数据       if($day=='01'and date('1',mktime(0,0,0,$month,$day,$year))=='Sunday'){           echo "<td>$day</td>";           $off='01';       }elseif($day=='01'and date('1',mktime(0,0,0,$month,$day,$year))=='Monday'){           //设置星期一的数据           echo "<td>$day</td>";           $off='02';       }elseif($day=='01'and date('1',mktime(0,0,0,$month,$day,$year))=='Tuseday'){           //设置星期二的数据           echo"<td>$day</td>";           $off='03';       }elseif($day=='01'and date('1',mktime(0,0,0,$month,$day,$year))=='Wednesday'){           //设置星期三的数据           echo "<td>$day</td>";           $off='04';       }elseif($day=='01'and date('1',mktime(0,0,0,$month,$day,$year))=='Thursday'){           //设置星期四的数据           echo "<td>$day</td>";           $off='05';       }elseif($day=='01'and date('1',mktime(0,0,0,$month,$day,$year))=='Friday'){           //设置星期五的数据           echo "<td>$day</td>";           $off='06';       }elseif($day=='01'and date('1',mktime(0,0,0,$month,$day,$year))=='Saturday'){           //设置星期六的数据           echo "<td>$day</td>";           $off='07';       }else{           //直接显示日期           echo "<td>$day</td>";       }       //递增while循环条件       $day++;       //设置开关变量       $off++;       //当$off大于7时,重起一行,并把$off变量置为1       if($off>7){           echo "</tr><tr>";           $off='01';       }else{           echo '';       }   }   //计算剩下的数据,使用空表格填充   for($i=$off;$i<=7;$i++){       echo "<td> </td>";   }   ?></tr>    </table></form></body></html>


回复讨论(解决方案)

while($day$date 的初值不对

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn