"include" different every day of the week
Moderator: General Moderators
"include" different every day of the week
I need aid with script PHP. I want to open a different page in "include" depending on the day of the week, with this scheme:
Monday, Tuesday, Wednesday, Thursday and Friday = > page01.inc
Saturdays = > page02.inc
Sundays = > page03.inc
You can help me in this problem. I am not very expert in PHP.
Thanks.
Monday, Tuesday, Wednesday, Thursday and Friday = > page01.inc
Saturdays = > page02.inc
Sundays = > page03.inc
You can help me in this problem. I am not very expert in PHP.
Thanks.
You can get the day of the week with time() and date().
Next, set up a switch/case:
Next, set up a switch/case:
Code: Select all
<?php
switch($day_of_week)
{
case 'Monday' or 'Tuesday' or [..etc]:
include('path/to/file1.php');
break;
// and so on
?>
Last edited by McGruff on Tue Aug 09, 2005 10:01 pm, edited 1 time in total.
I am not very expert in PHP and I am afraid that I need more aid. This it is the code that I have put in the page:
But it does not work. Today (Saturday) opens include of Monday. That I am making bad?
Code: Select all
<?php
switch($day_of_week)
{
case $day_of_week='Monday':
include('vidi01.inc');
break;
case $day_of_week='Tuesday':
include('vidi01.inc');
break;
case $day_of_week='Wednesday':
include('vidi01.inc');
break;
case $day_of_week='Thursday':
include('vidi01.inc');
break;
case $day_of_week='Friday':
include('vidi01.inc');
break;
case $day_of_week='Saturday':
include('visa01.inc');
break;
case $day_of_week='Sunday':
include('vido01.inc');
break;
}
?>Be careful with the difference between "=" and "==".
$var = 1 assigns a value to a var.
$var == 1 would be used to test if $var equals 1.
Try this:
$var = 1 assigns a value to a var.
$var == 1 would be used to test if $var equals 1.
Try this:
Code: Select all
<?php
switch($day_of_week)
{
case 'Monday' or 'Tuesday' or 'Wednesday' or 'Thursday' or 'Friday':
include('vidi01.inc');
break;
case 'Saturday':
include('visa01.inc');
break;
case 'Sunday':
include('vido01.inc');
break;
}
?>
Last edited by McGruff on Tue Aug 09, 2005 10:01 pm, edited 1 time in total.
Ooops - this works:
Code: Select all
<?php
switch($day_of_week)
{
case 'Monday':
include('vidi01.inc');
break;
case 'Tuesday':
include('vidi01.inc');
break;
case 'Wednesday':
include('vidi01.inc');
break;
case 'Thursday':
include('vidi01.inc');
break;
case 'Friday':
include('vidi01.inc');
break;
case 'Saturday':
include('visa01.inc');
break;
case 'Sunday':
include('vido01.inc');
break;
}
?>
Last edited by McGruff on Tue Aug 09, 2005 10:01 pm, edited 1 time in total.
I have completed script with this code and now works.
Thousands of thanks.
This forum is fantastic, I must a beer to you.

Code: Select all
<?php
$day = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday') ;
$date = date(w) ;
$day_of_week = "$day[$date]" ;
switch($day_of_week)
{
case 'Monday':
include('vidi01.inc');
break;
case 'Tuesday':
include('vidi01.inc');
break;
case 'Wednesday':
include('vidi01.inc');
break;
case 'Thursday':
include('vidi01.inc');
break;
case 'Friday':
include('vidi01.inc');
break;
case 'Saturday':
include('visa01.inc');
break;
case 'Sunday':
include('vido01.inc');
break;
}
?>This forum is fantastic, I must a beer to you.
Also is valid next code, simpler.
Thanks again.
Code: Select all
<?php
$day_of_week = date(w) ;
switch($day_of_week){
case 0:
include('vido01.inc');
break;
case 6:
include('visa01.inc');
break;
default:
include('vidi01.inc');
break;
}
?>