Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PHP: I\'m trying to force the background of my div to change everyday using a sw

ID: 3789511 • Letter: P

Question

PHP: I'm trying to force the background of my div to change everyday using a switch statement (required) but no luck. Could anyone comment? Here's what I've got:

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">
<meta name="robots" content="noindex,nofollow" />

<title>A2: Caterday Home</title>
<link id="mainStylesheet" href="css/styles.css" type="text/css" rel="stylesheet" />
   <style>
      
       div#wrapper {
           width:940px;
           margin:20px auto;
           padding:20px;
           background-color: #<?php echo $shade; ?>;
           }
      
       h2{
           font-size:2em;
           font-family:"comic-sans-ms", Cursive;
           color:#221fe0;
           clear:right;
           margin-bottom:7px;
           }
      
       img.cat {
           float:right;
           padding-left:20px;
           width:400px;
           }
      
   </style>
</head>

<body>

<div id="wrapper">
<main>
<header>
   <h1>Happy Cat-erday!<img src="images/kitten.jpg" alt="logo" class="kitten" id="kitten"></h1>
   <nav>
           <ul>
               <li><a href="#">Sample Link</a></li>
<li><a href="#">Sample Link</a></li>
<li><a href="#">Sample Link</a></li>
<li><a href="#">Sample Link</a></li>
<li><a href="#">Sample Link</a></li>
           </ul>
       </nav>
</header>


<h2 class="greeting">Here, everyday is Caterday!</h2>


<img src="images/monday.jpg" alt="Today's Cat" class="cat" id="cat"/>


<p>Scratch leg; meow for can opener to feed me cat not kitten around for hiss at vacuum cleaner yet hide when guests come over, but refuse to leave cardboard box for always hungry or playing with balls of wool. This human feeds me, i should be a god human is washing you why halp oh the horror flee scratch hiss bite, kick up litter put toy mouse in food bowl run out of litter box at full speed thinking longingly about tuna brine. Ignore the squirrels, you'll never catch them anyway loves cheeseburgers but cats making all the muffins cat not kitten around . Eat owner's food lick the plastic bag stare at wall turn and meow stare at wall some more meow again continue staring sleep on dog bed, force dog to sleep on floor and missing until dinner time.</p>

<p>Ears back wide eyed where is my slave? I'm getting hungry hide when guests come over licks your face asdflkjaertvlkjasntvkjn (sits on keyboard) knock over christmas tree. Scamper jump off balcony, onto stranger's head but give attitude purrr purr littel cat, little cat purr purr asdflkjaertvlkjasntvkjn (sits on keyboard) or and sometimes switches in french and say "miaou" just because well why not intently sniff hand. Eat from dog's food. Go into a room to decide you didn't want to be in there anyway. Walk on car leaving trail of paw prints on hood and windshield under the bed go into a room to decide you didn't want to be in there anyway kick up litter wake up wander around the house making large amounts of noise jump on top of your human's bed and fall asleep again make muffins. </p>

<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff hate dog loves cheeseburgers but climb leg pooping rainbow while flying in a toasted bread costume in space. Mark territory i am the best and pee in human's bed until he cleans the litter box i like big cats and i can not lie. Immediately regret falling into bathtub sweet beast lick butt and make a weird face for cats secretly make all the worlds muffins for human give me attention meow, so refuse to drink water except out of someone's glass catch mouse and gave it as a present. Flop over eats owners hair then claws head. Toy mouse squeak roll over.</p>
</main>
<footer>
<ul>
<li>Copyright &copy; 2016</li>
<li>All Rights Reserved</li>
<li><u><a href="http://edison.seattlecentral.edu/~dcoult01/web110/">Web design by Danielle Coulter</a></u></li>

</ul>
  
</footer>

</div><!--end wrapper-->

<p>Text provided by <a href="https://www.shopify.com/partners/blog/79940998-15-funny-lorem-ipsum-generators-to-shake-up-your-design-mockups" target="_blank">Hipster Ipsum</a>
       </p>
  
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
   <script type="text/javascript">
   $("document").ready(function(){
       $('.days a').click(function(e){//find all a tags inside class of seasons
e.preventDefault();//stop default submission
           var day = $(this).attr("href");//contents of href attribute of this element
           var stylesheet = $('#mainStylesheet');
           day = day.toLowerCase();
      
date_default_timezone_set('America/Los_Angeles');

$day = date('N');
          
           switch($day)
           {
               case '1':
               $('main header h2').html("Monday's mean nothing to a kitty");
               $('#cat').attr("src","images/monday.jpg");
               $('wrapper').html(background-color:antiquewhite);

               break;
           }
      
</script>


</body>

</html>

Explanation / Answer

I have made changes to your code, to calculate the day first in the beginning and assigning a color code to shade variable and using that in the div's style .

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex,nofollow" />
<title>A2: Caterday Home</title>
<?php
switch(date('N'))
{
case 1:$shade='456778'; break;
case 2:$shade='654448'; break;
case 3:$shade='356754'; break;
case 4:$shade='864687'; break;
case 5:$shade='ffff00'; break;
case 6:$shade='0ffff0'; break;
case 7:$shade='556778'; break;

} ?>
<link id="mainStylesheet" href="css/styles.css" type="text/css" rel="stylesheet" />
<style>
  
div#wrapper {
width:940px;
margin:20px auto;
padding:20px;
background-color: #<?php echo $shade; ?>;
}
  
h2{
font-size:2em;
font-family:"comic-sans-ms", Cursive;
color:#221fe0;
clear:right;
margin-bottom:7px;
}
  
img.cat {
float:right;
padding-left:20px;
width:400px;
}
  
</style>
</head>
<body>
<div id="wrapper">
<main>
<header>
<h1>Happy Cat-erday!<img src="images/kitten.jpg" alt="logo" class="kitten" id="kitten"></h1>
<nav>
<ul>
<li><a href="#">Sample Link</a></li>
<li><a href="#">Sample Link</a></li>
<li><a href="#">Sample Link</a></li>
<li><a href="#">Sample Link</a></li>
<li><a href="#">Sample Link</a></li>
</ul>
</nav>
</header>

<h2 class="greeting">Here, everyday is Caterday!</h2>

<img src="images/monday.jpg" alt="Today's Cat" class="cat" id="cat"/>

<p>Scratch leg; meow for can opener to feed me cat not kitten around for hiss at vacuum cleaner yet hide when guests come over, but refuse to leave cardboard box for always hungry or playing with balls of wool. This human feeds me, i should be a god human is washing you why halp oh the horror flee scratch hiss bite, kick up litter put toy mouse in food bowl run out of litter box at full speed thinking longingly about tuna brine. Ignore the squirrels, you'll never catch them anyway loves cheeseburgers but cats making all the muffins cat not kitten around . Eat owner's food lick the plastic bag stare at wall turn and meow stare at wall some more meow again continue staring sleep on dog bed, force dog to sleep on floor and missing until dinner time.</p>
<p>Ears back wide eyed where is my slave? I'm getting hungry hide when guests come over licks your face asdflkjaertvlkjasntvkjn (sits on keyboard) knock over christmas tree. Scamper jump off balcony, onto stranger's head but give attitude purrr purr littel cat, little cat purr purr asdflkjaertvlkjasntvkjn (sits on keyboard) or and sometimes switches in french and say "miaou" just because well why not intently sniff hand. Eat from dog's food. Go into a room to decide you didn't want to be in there anyway. Walk on car leaving trail of paw prints on hood and windshield under the bed go into a room to decide you didn't want to be in there anyway kick up litter wake up wander around the house making large amounts of noise jump on top of your human's bed and fall asleep again make muffins. </p>
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff hate dog loves cheeseburgers but climb leg pooping rainbow while flying in a toasted bread costume in space. Mark territory i am the best and pee in human's bed until he cleans the litter box i like big cats and i can not lie. Immediately regret falling into bathtub sweet beast lick butt and make a weird face for cats secretly make all the worlds muffins for human give me attention meow, so refuse to drink water except out of someone's glass catch mouse and gave it as a present. Flop over eats owners hair then claws head. Toy mouse squeak roll over.</p>
</main>
<footer>
<ul>
<li>Copyright &copy; 2016</li>
<li>All Rights Reserved</li>
<li><u><a href="http://edison.seattlecentral.edu/~dcoult01/web110/">Web design by Danielle Coulter</a></u></li>
</ul>
  
</footer>
</div><!--end wrapper-->
<p>Text provided by <a href="https://www.shopify.com/partners/blog/79940998-15-funny-lorem-ipsum-generators-to-shake-up-your-design-mockups" target="_blank">Hipster Ipsum</a>
</p>
  
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
<script type="text/javascript">
$("document").ready(function(){
$('.days a').click(function(e){//find all a tags inside class of seasons
e.preventDefault();//stop default submission
var day = $(this).attr("href");//contents of href attribute of this element
var stylesheet = $('#mainStylesheet');
day = day.toLowerCase();
  
date_default_timezone_set('America/Los_Angeles');
$day = date('N');
  
switch($day)
{
case '1':
$('main header h2').html("Monday's mean nothing to a kitty");
$('#cat').attr("src","images/monday.jpg");
  
break;
}
  
</script>

</body>
</html>