PHP:船长哦船长,我的开关案件很糟糕

时间:2014-04-06 18:58:48

标签: php switch-statement

我试图在这里构建一个简单的交换机案例演示,我让它在我的学校服务器上工作,现在我正在尝试将它带到我的服务器,因为本季度结束了。我不知道发生了什么,开关盒正在工作但不再是,我正在努力修复它。路径是好的,我已经通过文件向前和向后试图找到我的逻辑中的错误,寻找丢失的分号,以及我能想到的其他一切。我很难过,并且不确定问题是什么,但似乎我的交换机案例并没有提供任何东西而且在某种程度上被打破了。

开关盒在工作时,理想情况下会向客户端(浏览器)显示日期,海报图形和独特的背景图像。

页面显示方式的jpg:http://school.max-o-matic.com/itc240/_img/img_240a010sm.jpg 链接到页面:http://school.max-o-matic.com/itc240/itc240_a020/index.php

<?php
/*
 *  a3_Dates-Conditionals.php
 *
 *  Create a page with the following functionality:
 *  Use PHP to deliver a different image and bit of content
 *  for each weekday (Sunday to Saturday) using one PHP file.
 *
 *  STAGE1 - Build it static (check)
 *  STAGE2 - build with variables (test, check)
 *  STAGE3 - Build with conditionals
 */

//http://us1.php.net/manual/en/function.date.php
$today = date("D, M j");

$test = ' ';
//http://www.php.net/manual/en/control-structures.switch.php
$strSun = ' ';
$strMon = ' ';
$strTues = ' ';
$strWeds = ' ';
$strThurs = ' ';
$strFri = ' ';
$strSat = ' ';

$linkSun = 'bg_img01.jpg';
$linkMon = 'bg_img02.jpg';
$linkTues = 'bg_img03.jpg';
$linkWeds = 'bg_img04.jpg';
$linkThurs = 'bg_img05.jpg';
$linkFri = 'bg_img06.jpg';
$linkSat = 'bg_img07.jpg';

$linkPoster = ' ';//isn't setting

switch (intval(date("N"))) {
case 0:
    $strSun = 'class="current"';
    $todayIs = 'Sunday'; //isn't setting
    $linkSun = "bg_imgSpecial.jpg";
    $linkPoster = 'img_poster-01.jpg';
    break;
case 1:
    $strMon = 'class="current"';
    $todayIs = 'Monday';
    $linkMon = "bg_imgSpecial.jpg";
    $linkPoster = 'img_poster-02.jpg';
    break;
case 2:
    $strTues = 'class="current"';
    $todayIs = 'Tuesday';
    $linkTues = "bg_imgSpecial.jpg";
    $linkPoster = 'img_poster-03.jpg';
    break;
case 3:
    $strWeds = 'class="current"';
    $todayIs = 'New Comic book Day!';
    $linkWeds = "bg_imgComicBooks.jpg";
    $linkPoster = 'img_poster-04.jpg';
    break;
case 4:
    $strThurs = 'class="current"';
    $todayIs = 'Thursday';
    $linkThurs = "bg_imgSpecial.jpg";
    $linkPoster = 'img_poster-05.jpg';
    break;
case 5:
    $strFri = 'class="current"';
    $todayIs = 'Friday';
    $linkFri = "bg_imgSpecial.jpg";
    $linkPoster = 'img_poster-06.jpg';
    break;
case 6:
    $strSat = 'class="current"';
    $todayIs = 'Saturday';
    $linkSat = "bg_imgSpecial.jpg";
    $linkPoster = 'img_poster-07.jpg';
    break;
}

?>

 <!DOCTYPE html>
 <html lang="en">
 <head> <title>a3 | itc240 (w14)</title>
    <meta charset="utf-8">
    <link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
    <link rel="stylesheet" href="css/layout.css" type="text/css" media="all">
    <link rel="stylesheet" href="css/prettyPhoto.css" type="text/css" media="all">
    <link rel="stylesheet" href="css/style.css" type="text/css" media="all">
    <script type="text/javascript" src="js/jquery-1.6.js" ></script>
    <script type="text/javascript" src="js/cufon-yui.js"></script>
    <script type="text/javascript" src="js/cufon-replace.js"></script>
    <script type="text/javascript" src="js/Ubuntu_400.font.js"></script>
    <script type="text/javascript" src="js/Ubuntu_700.font.js"></script>
    <script type="text/javascript" src="js/bgSlider.js" ></script>
    <script type="text/javascript" src="js/script.js" ></script>
    <script type="text/javascript" src="js/pages.js"></script>
    <script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
    <script type="text/javascript" src="js/bg.js" ></script>
    <script type="text/javascript" src="js/tabs.js"></script>
    <script type="text/javascript" src="js/jquery.prettyPhoto.js"></script>
    <!--[if lt IE 9]>
        <script type="text/javascript" src="js/html5.js"></script>
    <![endif]-->
    <!--[if lt IE 7]>
        <div style='clear:both;text-align:center;position:relative'>
            <a href="http://www.microsoft.com/windows/internet-explorer/default.aspx?ocid=ie6_countdown_bannercode">
 <img src="http://storage.ie6countdown.com/assets/100/images/banners/warning_bar_0000_us.jpg" border="0"  alt="" /></a>
        </div>
    <![endif]-->
 </head>
 <body id="page1">
    <div class="spinner"></div>
    <div id="bgSlider"></div>
    <div class="extra">
        <div class="main">
            <div class="box">
 <!-- header --> <header> <h1><a href="index.html"     id="logo">Max |        <sup>itc</sup>240</a></h1>
                    <nav>
                        <ul id="menu">
                            <li> <br > <img src="images/<?=$linkPoster;?>" alt=""> </li>
                            <li><a href="#"><strong><?=$today;?></strong></a></li>


                        </ul>
                    </nav>
                </header>
<!--content -->
                <article id="content">
                    <div class="ic"><!--Content Here... --</div>
                </article id="content">

<!-- / content -->
            </div>
        </div>
        <div class="block"></div>
    </div>
    <div class="bg1">
        <div class="main">
<!-- footer -->
            <footer>
                <div class="bg_spinner"></div>

                <ul class="pagination">
                    <li <?=$strSun;?> ><a href="images/<?=$linkSun;?>">S</a></li>
                    <li <?=$strMon;?> ><a href="images/<?=$linkMon;?>">M</a></li>
                    <li <?=$strTues;?> ><a href="images/<?=$linkTues;?>">T</a></li>
                    <li <?=$strWeds;?> ><a href="images/<?=$linkWeds;?>">W</a></li>
                    <li <?=$strThurs;?> ><a href="images/<?=$linkThurs;?>">Th</a></li>
                    <li <?=$strFri;?> ><a href="images/<?=$linkFri;?>">F</a></li>
                    <li <?=$strSat;?> ><a href="images/<?=$linkSat;?>">S</a></li>
                </ul>


                <div class="col_1">
                    <a href="index.html" id="footer_logo">ZZZ</a>
                </div>
                <div class="col_2">
                     <a rel="nofollow" href="http://www.max-o-matic.com/" target="_blank">&nbsp;</a>
                    <!-- {%FOOTER_LINK} -->
                </div>
            </footer>
<!-- / footer-->
        </div>
    </div>
    <script type="text/javascript"> Cufon.now(); </script>
    <script>
    $(window).load(function() {
        $('.spinner').fadeOut();
        $('body').css({overflow:'inherit'})
    })
    </script>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

根据the documentation,PHP date函数N格式说明符返回1-7范围内的值。你的switch语句期望0-6。今天是星期日,所以date调用返回7并且你的switch语句没有处理它。

答案 1 :(得分:1)

我只是在自己的服务器上运行代码,

首先,日期(“N”)返回1-7,而不是0到6,所以你会丢失一个。 作为一种习惯,总是添加默认值:到一个案例开关,这样你就可以捕捉到意想不到的结果。

尝试使用日期(“w”)代替。 (小写w)

除此之外,你的代码很好