Page 1 of 2
PHP Daily Schedule Rotation
Posted: Thu Sep 24, 2009 5:23 pm
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!
Re: PHP Daily Schedule Rotation
Posted: Thu Sep 24, 2009 9:00 pm
by Griven
The following code will return the full textual representation of the day of the week.
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.
Re: PHP Daily Schedule Rotation
Posted: Thu Sep 24, 2009 9:09 pm
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');
}
Re: PHP Daily Schedule Rotation
Posted: Thu Sep 24, 2009 9:10 pm
by CONFUSIONUK
Griven wrote:The following code will return the full textual representation of the day of the week.
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 ^
Re: PHP Daily Schedule Rotation
Posted: Thu Sep 24, 2009 9:19 pm
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.
Re: PHP Daily Schedule Rotation
Posted: Thu Sep 24, 2009 9:27 pm
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?
Re: PHP Daily Schedule Rotation
Posted: Thu Sep 24, 2009 9:32 pm
by CONFUSIONUK
There you go make life easier if you can just see what i done so far
Ohhh and the filenames do have capitals i just forgot to refresh the browser on dreamweaver
Re: PHP Daily Schedule Rotation
Posted: Thu Sep 24, 2009 9:37 pm
by Griven
[deleted]
Re: PHP Daily Schedule Rotation
Posted: Thu Sep 24, 2009 9:41 pm
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.
Re: PHP Daily Schedule Rotation
Posted: Thu Sep 24, 2009 9:49 pm
by CONFUSIONUK
It is live yes image below is it being displayed on the site!
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>
Re: PHP Daily Schedule Rotation
Posted: Thu Sep 24, 2009 10:04 pm
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.
Re: PHP Daily Schedule Rotation
Posted: Thu Sep 24, 2009 10:09 pm
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
Re: PHP Daily Schedule Rotation
Posted: Thu Sep 24, 2009 10:17 pm
by CONFUSIONUK
The "Default" you are seeing is coming from within the default.html file
Re: PHP Daily Schedule Rotation
Posted: Thu Sep 24, 2009 11:59 pm
by Griven
Hmm... Are your filenames "Monday.html" or "monday.html"? If they're lowercase, try this:
Re: PHP Daily Schedule Rotation
Posted: Fri Sep 25, 2009 8:44 am
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