PHP: Captain Oh Captain, My Switch Case Sucks -
i'm trying build simple switch case demo here , had working on school server , trying carry on server quarter over. don't know happened, switch case working no longer , trying repair it. paths good, , i've gone through file forwards , backwards trying find error in logic, looked missing semicolons, , else can think do. i'm stumped , not sure issue seems switch case isn't delivering , somehow broken.
the switch case, when working, ideally display date, poster graphic , unique background image client (browser).
jpg of how page display: http://school.max-o-matic.com/itc240/_img/img_240a010sm.jpg link page: http://school.max-o-matic.com/itc240/itc240_a020/index.php
<?php /* * a3_dates-conditionals.php * * create page following functionality: * use php deliver different image , bit of content * each weekday (sunday saturday) using 1 php file. * * stage1 - build static (check) * stage2 - build variables (test, check) * stage3 - build 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"> </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>
i ran code on own server,
first of all, date("n") returns 1-7, , not 0 6, you'll missing one. habit, add default: case switch, can catch unexpected results.
try using date("w") instead. (lowercase w)
other that, code fine
Comments
Post a Comment