PHP newbi - need help

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

Post Reply
jwan84
Forum Newbie
Posts: 7
Joined: Wed Mar 26, 2008 9:51 pm

PHP newbi - need help

Post by jwan84 »

i have question about coding.
i have a website that currently has

include("main content");

to my main content.
i want the main content to cycle every 24hours. so it displays different content
every day.

like day one it shows
"main content 1"
day two "main content 2"
day 3 main content 3 .... and so on
can this be done?
AMCH
Forum Commoner
Posts: 31
Joined: Sun Mar 30, 2008 4:39 pm

Re: PHP newbi - need help

Post by AMCH »

Hi there,

This can be done. Try something similar to the following:

As an example I am going to show you how to make it display based on which day of the week it is.

Code: Select all

// date("N") is a built in php function to establish the day of the week based on a number representation,
// 1 being Monday etc... it uses your system time/calendar to establish which day it is.
 
$day_to_include = date("N");
 
// the following concatenates the variable onto the end of "main_content"
 
$day_to_include = "main_content".$day_to_include."html";
 
// the following includes a file that is equal to the variable
 
include "$day_to_include";
With the above example:

If the day was Monday it will include "main_content1.html",
Tuesday will include "main_content2.html"... and so on...

Hope this helps.

Kind Regards
AMCH
jwan84
Forum Newbie
Posts: 7
Joined: Wed Mar 26, 2008 9:51 pm

Re: PHP newbi - need help

Post by jwan84 »

thax so much.
life saver!
Post Reply