SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2008
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    "Sunday" not working in days of week script

    I was given this simple days of the week script to display content specific for each day of the week. Every day works fine except for Sunday. I've gone character by character through the code, but can't seem to find any inconsistencies with the rest of the days that work. Can anyone find the issue?
    HTML Code:
    <?php
     
        $myEvents=array();
       
        $myEvents[0]['title']='<h2>Tonight! <!--Monday--></h2>';
        $myEvents[0]['description']='<h6>During Dinner</h6>
      <p class="left-spacer">Happy Hour 4-7</p>
      <h6>Late Night</h6>
      <h3 class="left-spacer">In The Biz @101</h3>
      <p class="left-spacer">Our version of hospitality night cannot be topped on the fun scale. Great drink specials, DJ starting at 10:30, and ROCK BAND on the big screen! That\'s right folks, bring your musical A game under our stage light and compete for free drinks and prizes. We like to call it Rock Star Treatment 101.</p>
      <p class="left-spacer">OTHER SPECIALS INCLUDE:<br />
    Free Bottle of Liquor for groups of 10 or more!<br />
                            $4 Top Shelf<br />
                            $2 Bottles Bud, Bud Light, Miller Lite Drafts!<br />
               25% Off All Food!</p>';
       
        $myEvents[1]['title']='<h2>Tonight! <!--Tuesday--></h2>';
        $myEvents[1]['description']='<h6>During Dinner</h6>
      <p class="left-spacer">Happy Hour 4-7<br /
      	Live Jazz Vocalist</p>
      <h6>Late Night</h6>
      <h3 class="description">All You Can Drink <span class="mint-link"><a href="../mint/index.html">@MINT</a></span></h3>
      <p class="description">The hottest college crowd in town lives at Mint Lounge on Tuesday nights. Best drink specials, best DJ, best guests and not much more to say.</p>
      <p class="description">THE DEAL:<br />
                  						All you Can Drink Wells, Champagne and Champagne Martinis from 10PM-1AM<br />
    $8 Cover for Guys<br />
    $5 Cover for Ladies</p>';
       
        $myEvents[2]['title']='<h2>Tonight! <!--Wednesday--></h2>';
        $myEvents[2]['description']='<h6>During Dinner</h6>
      <p class="left-spacer">Happy Hour 4-7<br />
      	3-Piece Jazz Band</p>
        <p class="left-spacer">Celebrate the middle of the week at 101, and enjoy our Live Jazz band during dinner to sooth you through the rest of the week.</p>';
       
        $myEvents[3]['title']='<h2>Tonight! <!--Thursday--></h2>';
        $myEvents[3]['description']='<h6>During Dinner</h6>
      <p class="description">Happy Hour 4-7<br />
      	Live Acoustic guitar &amp; vocalist</p>
      <h6>Late Night</h6>
      <h3 class="description">Soiree</h3>
      <p class="description">Tallahassee\'s classiest Urban Night is at 101&amp;MINT every Thursday Night from 10PM-2AM! Strict dress code enforced, so dress to impress.</p>
      <p class="description">SPECIALS INCLUDE:<br />
                  						2 for 1 Hennessy &amp; Grey Goose<br />
    $5 Sex on the Beach<br /></p>';
       
        $myEvents[4]['title']='<h2>Tonight! <!--Friday--></h2>';
        $myEvents[4]['description']='<h6>During Dinner</h6>
      <p class="description">Happy Hour 4-7<br />
      	Live Acoustic guitar &amp; vocalist</p>
      <h6>Late Night</h6>
      <h3 class="description">23+ Fridays <span class="mint-link"><a href="../mint/index.html">@MINT</a></span></h3>
      <p class="description">Friday nights at 101&amp;Mint are your chance to escape the college crowd. You\'ve been longing for a place to party with classy individuals, stimulating conversation and great cocktails, and Tally\'s newest 23+ hangout is the answer. Doors open at 10PM -- see you here!</p>
      <p class="description">THE DEAL:<br />
                  						Live Entertainment All Night<br />
    Ladies Get in Free All night<br />
    2-4-1 Crown &amp; Goose<br />
    Must be 23+ to enter<br />
    Dress Code Strictly Enforced</p>';
       
        $myEvents[5]['title']='<h2>Tonight! <!--Saturday--></h2>';
        $myEvents[5]['description']='<h6>During Dinner</h6>
      <p class="left-spacer">Happy Hour 4-7</p>
      <h6>Late Night</h6>
      <h3 class="description">Seductive Saturdays @101&amp;MINT</h3>
      <p class="description">Duel locations, Duel DJs, collectively the HOTTEST spot to party on Saturday night. Enough said.</p>
      <p class="description">THE DEAL:<br />
                  						$2 Wells Until 1AM<br />
    $3 Calls Until 1AM<br />
    Ladies get in Free until 11 (21+ only; $5 for under)<br />
    Free Champagne bottles to groups of 4 or more ladies until 11<br />
    Gentlemen $7 Until 11 (21+)<br />
    Free Entry to Mint All night with dinner receipt from 101 ($25 min per person)</p>';
       
        $myEvents[6]['title']='<h2>Tonight! <!--Sunday--></h2>';
        $myEvents[6]['description']='<h3 class="description">All Day Happy Hour</h3>
    <p class="description">Much like Saturday, our doors open on Sunday at 4PM for dinner and Happy Hour. Once Happy Hour ends -- wait, actually Happy Hour never ends! That\'s right, every Sunday evening is 50% OFF ALL DRINKS AND 25% OFF ALL FOOD ALL NIGHT! This is the kind of deal that may make you rethink your Sunday traditions...</p>';
       
        $today=date("w")-1;
       
        echo $myEvents[$today]['title'];
        echo $myEvents[$today]['description'];
     
    ?>

  2. #2
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,396
    Mentioned
    61 Post(s)
    Tagged
    0 Thread(s)
    You want $today to be 6 (to point to Sunday's title/description) but $today will range between -1 and 5. This is because of the line $today=date("w")-1;

    date("w") will return 0 for Sunday through to 6 for Saturday so there are a few options that you could take. Either restructure your $myEvents array to run from Sunday to Saturday (and using $today=date("w");) or keep the array as it is right now and use $today=date("N")-1; (ie, only change the w to an N). The latter is because the N returns the ISO-8601 value for that day running from 1 (for Monday) to 7 (for Sunday) and when you take one away, the $myEvents key numbers for each day will match up. You could also just change both occurrences of $myEvents[6] to $myEvents[-1] but that would make less sense than any of the two previous suggestions.

    For full details, please see the PHP Manual page for date().
    Salathe
    Software Developer and PHP Manual Author.

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2008
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! Changing the array to start with Sunday as [0] worked perfectly. I did try changing the "w" to "N" at first, and was unsuccessful. Even though the problem is solved, I'm wondering why that didn't work. I know very little about PHP, but could it do with me using the UTF-8 charset rather than ISO? Just curious.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •