Page 1 of 1

"include" different every day of the week

Posted: Sat Jan 24, 2004 1:24 am
by pirolilla
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.

Posted: Sat Jan 24, 2004 1:31 am
by McGruff
You can get the day of the week with time() and date().

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

?>

Posted: Sat Jan 24, 2004 1:36 am
by pirolilla
I am going to prove.

Thank you very much.

The express of the answer surprises to me.

Posted: Sat Jan 24, 2004 2:05 am
by pirolilla
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:

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; 
}
?>
But it does not work. Today (Saturday) opens include of Monday. That I am making bad?

Posted: Sat Jan 24, 2004 2:19 am
by McGruff
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:

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; 
}
?>

Posted: Sat Jan 24, 2004 2:38 am
by pirolilla
With that code it does not load any of the "includes". :(

Thank you very much anyway.

Posted: Sat Jan 24, 2004 2:54 am
by McGruff
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;
}
?>

Posted: Sat Jan 24, 2004 3:07 am
by pirolilla
I have completed script with this code and now works.

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; 
}
?>
Thousands of thanks.

This forum is fantastic, I must a beer to you.

:lol: :lol: :lol: :lol: :lol:

Posted: Sat Jan 24, 2004 3:47 am
by pirolilla
Also is valid next code, simpler.

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;
}
?>
Thanks again.

Posted: Sat Jan 24, 2004 4:53 am
by McGruff
Yes - much better.