Jump to content

Archived

This topic is now archived and is closed to further replies.

mumford

Rotate Dynamic Content Every Day

Recommended Posts

Hi

I am VERY new tp php, and found this script on php freaks, it is a randomizer script

[code]<?
/* Directory Structure
/index1.htm
/index2.htm

*/
srand((double)microtime()*1000000);
$num = rand(1,2);

include ('index'.$num.'.htm');

?>[/code]

What I need to happen on my website is 3 blocks of text each in its own div to change every day (5 days to be precise), I got the above to work but as I said it is just a randomizer so each time you refresh it changes.

Also my dynamic content pages will sit in its own folder, and I would like to name the pages depending on what they are, eg, capetown.htm, garden-route.htm

Does that make sense, hope someone can help me!

thanks

Share this post


Link to post
Share on other sites
it might be best for the script to maybe check for a time of day?

For example. If it is past midnight, the date is different, and the info hasn't already been changed, then save information in the database. (or even a file, who cares in this situation).

then for that entire day it will show "whatever.htm" and at 12 midnight (or later) whenevery someone opens the page, the first person to open it after midnight, it will set this new information accordingly.

The things you'll need to look into to make this work is file reading/writing and date functions. that should be enough to get that idea done.

Share this post


Link to post
Share on other sites
or use a counter script from a database field like:
switch ($row['counter']){
case 1:
echo 'stuff #1';
break;
}
and keep doing that for each instance
then if it's the following day, update the database using a timestamp checker.

Share this post


Link to post
Share on other sites
Thanks fo rthe quick replies, like I sadi I know very lttle PHP (at the moment!)

So I would have to create a database where all of my text divs would sit, then call them from the homepage?

Share this post


Link to post
Share on other sites
Can anyone else shed some more light on how I go about setting this up to switch content on a daily basis, do I really have to set up a database?....... there will only be about 5 alternative text blocks

Share this post


Link to post
Share on other sites
The sort of thing I'd do is use php to get today's date and determine what day number of the year it is.  Then I'd modulo 5 that and based on the remainder, I'd include day0.php, day1.php etc.  No database needed, no counter needed.

Share this post


Link to post
Share on other sites
sounds exactly what i need, but I dont even know where to start to get that working, your help or guidance would be much appreciated.

thanks

Share this post


Link to post
Share on other sites
[code]<?php
$doty = date("z"); // day of the year
$doty_remainder = $doty % 5 ; // remainder of day of the year divided by 5
$the_file = "path/to/my/files/news_". $doty_remainder. ".php"; // edit path info to suit
include($the_file);
?>[/code]

That'll need files news_0.php, news_1.php ..... news_4.php. Good luck.

Share this post


Link to post
Share on other sites
Andy B, that looks like it will be the best response I have received over 2 days, thank you!

I suppose if I need to have other items that rotate on a daily basis I just inser the same code but change the filenames eg

[code]<?php
$doty = date("z"); // day of the year
$doty_remainder = $doty % 5 ; // remainder of day of the year divided by 5
$the_file = "[b]dynamic/offers[/b]_". $doty_remainder. ".php"; // edit path info to suit
include($the_file);
?>[/code]

Also as a matter of interest if I did want those 5 pages to rotate randomly is there a way of adjusting the code you gave or would it be something different entirely?

Thanks again

Share this post


Link to post
Share on other sites
Answer to the first question is "Yes".

as to the second: to have a randomly selected page (from a lsit), I'd use code like this:

[code]<?php
$pages = array("page1.php", "gardening.php", "fishing.php", "whatever.php"); // as many as you want
$the_file = $pages[rand(0,count($pages)-1)]; // select a random page from the array
include($the_file);
?>[/code]

You can add file names to the array and the rest of the code can remain as written.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.