PHP Daily Schedule Rotation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
CONFUSIONUK
Forum Newbie
Posts: 17
Joined: Thu Sep 24, 2009 5:15 pm
Location: Winchester, UK

PHP Daily Schedule Rotation

Post by CONFUSIONUK »

Really sorry if this is in the wrong section of the forum as im new here.
Basically i want to scrap my current js content rotator on my site that i got at the moment and replace it with a 100% PHP and mysql if needed schedule rotator.

Above says most of what im after but just incase.
I have a schedule on the homepage of my website that changes daily (example: monday.html, tuesday.html and soo on) each file is loaded for the current day.

If there is a current pre-built script that would be great, if not would anyone be able to show me the script i would need to use, my php is still very rusty as im fairly new to the language but hopeing to go somewhere with it!
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: PHP Daily Schedule Rotation

Post by Griven »

The following code will return the full textual representation of the day of the week.

Code: Select all

date('l'); //that's a lowercase L
Assuming that your HTML files are named after each day of the week (Monday.html, etc.), here is how you would go about loading them up in the fashion that you describe.

Code: Select all

 
$date = date('l');
include($date .'.html');
 
Voila.

More details on the date function here.
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: PHP Daily Schedule Rotation

Post by Griven »

If you want a bit more fault tolerance, you can add a bit more code. This is handy just in case a file gets renamed or deleted on accident.

Code: Select all

$date = date('l');
  //Let's concatenating the day of the week and '.html' into one variable for ease of use
$page = $date  .'.html';  
 
  //This checks to see if the filename exists in the current directory.
  //If it does, it pulls the page up.  If not, it pulls up a default page.
if (file_exists($page)){ 
    include($page);
} else {
    include('default.html');
}
User avatar
CONFUSIONUK
Forum Newbie
Posts: 17
Joined: Thu Sep 24, 2009 5:15 pm
Location: Winchester, UK

Re: PHP Daily Schedule Rotation

Post by CONFUSIONUK »

Griven wrote:The following code will return the full textual representation of the day of the week.

Code: Select all

date('l'); //that's a lowercase L
Assuming that your HTML files are named after each day of the week (Monday.html, etc.), here is how you would go about loading them up in the fashion that you describe.

Code: Select all

 
$date = date('l');
include($date .'.html');
 
Voila.

More details on the date function here.
Sorry when i ment im a bit rusty at php i meant i really dont have a great deal in putting it all together!

Below is how im assuming you mean to put it together?

Code: Select all

 
<?php
date('l'); //that's a lowercase L
$date = date('l');
include($date .'.html');
?>
 

if i put this in to schedule.php in the schedule/ directory and the day file are in there will it just start readint them files on the right day?

monday.html
tuesday.html
wednesday.html
thursday.html
friday.html
saturday.html
sunday.html

these are the 7 file name ^
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: PHP Daily Schedule Rotation

Post by Griven »

CONFUSIONUK wrote:Below is how im assuming you mean to put it together?

Code: Select all

 
<?php
date('l'); //that's a lowercase L
$date = date('l');
include($date .'.html');
?>
 
That's absolutely how it should be put together.
CONFUSIONUK wrote: if i put this in to schedule.php in the schedule/ directory and the day file are in there will it just start readint them files on the right day?
Yes. This should work just fine for you. Let me know if it doesn't.
User avatar
CONFUSIONUK
Forum Newbie
Posts: 17
Joined: Thu Sep 24, 2009 5:15 pm
Location: Winchester, UK

Re: PHP Daily Schedule Rotation

Post by CONFUSIONUK »

Ahhh no i got it sorry about that lol, had the filenames still with lowercase just one problem its loading the default and not the friday.html file?
User avatar
CONFUSIONUK
Forum Newbie
Posts: 17
Joined: Thu Sep 24, 2009 5:15 pm
Location: Winchester, UK

Re: PHP Daily Schedule Rotation

Post by CONFUSIONUK »

Image


There you go make life easier if you can just see what i done so far :P

Ohhh and the filenames do have capitals i just forgot to refresh the browser on dreamweaver
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: PHP Daily Schedule Rotation

Post by Griven »

[deleted]
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: PHP Daily Schedule Rotation

Post by Griven »

Have you previewed this in a web browser, or just in Dreamweaver?

I don't use Dreamweaver, but I don't think it displays dynamic content such as PHP. If you want to see the results of your code, you'll have to pull it up in an actual browser.
User avatar
CONFUSIONUK
Forum Newbie
Posts: 17
Joined: Thu Sep 24, 2009 5:15 pm
Location: Winchester, UK

Re: PHP Daily Schedule Rotation

Post by CONFUSIONUK »

It is live yes image below is it being displayed on the site!

Image

Code: Select all

 
<div class="homeTop"><strong>CHECK OUT TODAYS LIVE SHOWS BELOW<br />
  <span class="smallPrint">a glimpse at our day line up</span></strong></div>
<div class="homeContent">Default</div>
 
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: PHP Daily Schedule Rotation

Post by Griven »

That's weird, but I'm pretty sure it doesn't come from the code I gave you. Nowhere in that code does it say "Default". It does say "default.html", but that's quite different. Do a search on your code for the word "Default", matching the capital D.

If nothing else, try changing the code on schedule.php to specify the schedules directory within the $page variable.

I've got to run for now. I'll check back in an hour or two.
User avatar
CONFUSIONUK
Forum Newbie
Posts: 17
Joined: Thu Sep 24, 2009 5:15 pm
Location: Winchester, UK

Re: PHP Daily Schedule Rotation

Post by CONFUSIONUK »

I was thinking maybe because it being included on the index.php which is a directory behind but then the default.html file is still displaying so im completely clueless :S
User avatar
CONFUSIONUK
Forum Newbie
Posts: 17
Joined: Thu Sep 24, 2009 5:15 pm
Location: Winchester, UK

Re: PHP Daily Schedule Rotation

Post by CONFUSIONUK »

The "Default" you are seeing is coming from within the default.html file
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: PHP Daily Schedule Rotation

Post by Griven »

Hmm... Are your filenames "Monday.html" or "monday.html"? If they're lowercase, try this:

Code: Select all

$date = strtolower(date('l'));
User avatar
CONFUSIONUK
Forum Newbie
Posts: 17
Joined: Thu Sep 24, 2009 5:15 pm
Location: Winchester, UK

Re: PHP Daily Schedule Rotation

Post by CONFUSIONUK »

Right the script does work fine now
BUT
how can i change the $page variable so i can use files in a sub directory of the original
Post Reply