By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,566 Members | 1,733 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,566 IT Pros & Developers. It's quick & easy.

PHP Include - file of the day

P: 5
Hi,

The best description I can think of for what | am looking for is 'Content Rotator'.
I know such scripts are available in javascript but I am hoping to find one in PHP.

Is it possible to have a list of file names, say one one for each day/week/ or month,
and then pass the appropriate file name to a PHP include statement?

Clearly I am not a PHP programmer.

Your help much appreciated.

Thanks
Harry
Jul 21 '07 #1
Share this Question
Share on Google+
7 Replies


P: 22
Hey,
There alot of ways you could do this. One way would be to make a txt file and seperate each name with a |. Then use a script like this.
[php]
<?php
//Name Rotator//
$fileofnames = 'names.txt';
if(file_exists($fileofnames))
{
$namesfile = file_get_contents($fileofnames);
$namesfile = explode('|' , $namesfile);
$date = date('j');
$date = $date-1;
echo $namesfile[$date];
}
else
{
echo 'No file';
}
?>
[/php]
That would choose names out of a file split by | so if my file's contents was
pie|dog|mouse|cat|tyler|bah|tyler|bah|something|et c|blah|blah|blah| etc...
it would show the 21st entry today.

If you wanted to change the rotation times you can go to
date() on php.net
and change the current "J" in
$date = date('j');
to somthing like h (for hours)

Hope this helps!
~Tyler
Jul 22 '07 #2

P: 5
Hey,
If you wanted to change the rotation times you can go to
date() on php.net
and change the current "J" in
$date = date('j');
to somthing like h (for hours)

Hope this helps!
~Tyler
Hi,

Thanks for your help. I checked out the date function as you suggested and after reading about arrays I got to the following.

<div class="foo">

<?php
$link = array();
$link["22"]= "foo1.htm";
$link["23"]= "foo2.htm";
$link["24"]= "foo3.htm";
$link["25"]= "foo4.htm";
$link["26"]= "foo5.htm";
$link["27"]= "foo6.htm";
$link["28"]= "foo7.htm";
$today = date("d");
include ($link["$today"]);
?>

</div>

Provided I build the array for 31 days it will load new content each day for a month.

Alternatively I could change date("d"), to the appropriate date value, and adjust the array, so that a new page is loaded once a week, once a month, or even for each day of the year.

Harry
Jul 22 '07 #3

kovik
Expert 100+
P: 1,044
Hi,

Thanks for your help. I checked out the date function as you suggested and after reading about arrays I got to the following.

<div class="foo">

<?php
$link = array();
$link["22"]= "foo1.htm";
$link["23"]= "foo2.htm";
$link["24"]= "foo3.htm";
$link["25"]= "foo4.htm";
$link["26"]= "foo5.htm";
$link["27"]= "foo6.htm";
$link["28"]= "foo7.htm";
$today = date("d");
include ($link["$today"]);
?>

</div>

Provided I build the array for 31 days it will load new content each day for a month.

Alternatively I could change date("d"), to the appropriate date value, and adjust the array, so that a new page is loaded once a week, once a month, or even for each day of the year.

Harry
Thank you for using an array instead of a file. :-D Using a file would have been so wasteful. Though, I'd suggest you use your database, but I assume you will in the future when you want to make your updates easier.

And so you know, it's completely unnecessary to put quotes around the $today variable, and the same goes for every number in your array.
Jul 22 '07 #4

P: 5
Thank you for using an array instead of a file. :-D Using a file would have been so wasteful. Though, I'd suggest you use your database, but I assume you will in the future when you want to make your updates easier.

And so you know, it's completely unnecessary to put quotes around the $today variable, and the same goes for every number in your array.
Hi,

All thanks to you, this was my first time using PHP. Taking what you provided I was able to look at W3schools with more understanding, to end up with the array.

So far as the DB is concerned I dont have one, I read somewhere earlier that you can access MS Excel thru PHP so if it becomes an issue.I can look at that or hunt for some freeware DB.

I didnt know about the quote marks ..........just goes to prove you cant rely on 'cut n paste'.... LOL

Maybe I should think about generating an update to an archieve list with a link for the previous day's article!....Guess I'll leave that awhile tho.

Cheers
Harry
Jul 22 '07 #5

kovik
Expert 100+
P: 1,044
All thanks to you, this was my first time using PHP. Taking what you provided I was able to look at W3schools with more understanding, to end up with the array.
Good for taking the initiative. :-D

So far as the DB is concerned I dont have one, I read somewhere earlier that you can access MS Excel thru PHP so if it becomes an issue.I can look at that or hunt for some freeware DB.
You don't have MySQL? Are you serious? Who is your web host?

I didnt know about the quote marks ..........just goes to prove you cant rely on 'cut n paste'.... LOL
Where did you copy and paste that from? Sounds like a website by an inexperienced programmer. Please keep in mind that there are no qualifications for programmers to meet before they are allowed to write a tutorial, so always keep a bit of skepticism and look at more resources than one.

Maybe I should think about generating an update to an archieve list with a link for the previous day's article!....Guess I'll leave that awhile tho.
Databasing would solve that easily.
Jul 23 '07 #6

P: 5
Good for taking the initiative. :-D



You don't have MySQL? Are you serious? Who is your web host?


Databasing would solve that easily.
MYSQL is available for 'free' provided I upgrade to hosting package with a bigger band width, but I wont really need it until I do something worth publishing.......which I havent.......yet.

Harry
Jul 23 '07 #7

kovik
Expert 100+
P: 1,044
MYSQL is available for 'free' provided I upgrade to hosting package with a bigger band width, but I wont really need it until I do something worth publishing.......which I havent.......yet.

Harry
What a horrible hosting company... MySQL is 'free' anyway. That's why so many of us use it. You can find hosting for free with MySQL and a usable amount of bandwidth if you take the time to look.
Jul 23 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.