Page 1 of 1

php codeing help

Posted: Mon Apr 21, 2008 8:41 pm
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 7days. so it displays different content
every week.

like week one it shows
"main content 1"
week two "main content 2"
week 3 main content 3 .... and so on
can this be done?

Re: php codeing help

Posted: Mon Apr 21, 2008 8:58 pm
by Christopher

Code: Select all

$filename = 'main_content' . (date('w') + 1) . '.php';
include $filename;

Re: php codeing help

Posted: Mon Apr 21, 2008 11:12 pm
by jwan84
thank you,
but i have 1 more question,
would this code return back to the first "main content" after the last "main content"

example,
lets say i have 5 different main content i want to cycle every week,
would it show main content #1 on week 6?
and content #2 on week 7 and so on...

what is the code for that?

Re: php codeing help

Posted: Tue Apr 22, 2008 12:59 am
by Christopher
For any date information look at the date() function. You probably want to get the modulus from dividing the week of the year by the number of week in the rotation.

http://us.php.net/manual/en/function.date.php

http://us.php.net/manual/en/language.op ... hmetic.php