Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using php to change content depending on day of week

    So I'm setting up a specials page in my beta website. I've been teaching myself most of the building and this is my only problem left.

    So what I need is some type of scripting to grab information for example Monday and post it when monday comes around. Then Tuesday it grabs tuesday information and etc etc.

    Thanks.

  • #2
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,387
    Thanks
    8
    Thanked 1,077 Times in 1,068 Posts
    I assume you're already using PHP on your page, so your page is
    probably called "index.php" instead of "index.html"?

    You'll use the PHP date function to get the "day of week".
    It will be based off of your webhost's timezone (unless it's really
    important to use your own).

    You didn't specify how your "information" is stored.
    A text file, something in a database??

    PHP Code:
    <?php

    // Get day of week (0=SUN, 1=MON ... 6=SAT)
    $day=date("w");

    // What to do with it ... not enough information from you to determine this part ...
    if($day == 0){
    // it's Sunday
    }
    if(
    $day == 1){
    // it's Monday
    }

    // etc.

    ?>
    Last edited by mlseim; 12-21-2010 at 01:55 AM.

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    All my information is in a .txt file on the server. Should I continue to use this file or should I change it to a different format.

  • #4
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,387
    Thanks
    8
    Thanked 1,077 Times in 1,068 Posts
    .txt is fine ...
    Do you have that part figured-out already?
    You're able to display the text you want?

  • #5
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeah I think I figured it out I decided not to use a back end database. Instead I'm using a echo function so it prints the special. Thanks so much.

  • #6
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,387
    Thanks
    8
    Thanked 1,077 Times in 1,068 Posts
    If you were to code several .txt files like ...

    t0.txt, t2.txt, t7.txt ...

    You could automatically reference it by using that digit ...

    PHP Code:
    <?php

    $day
    =date("w");
    $file="t".$day.".txt";

    // anywhere on your page, you include the file.
    //include($file);

    ?>

    <html>
    <body>
    Your page .. blah blah<br><br>

    <?php include($file);?>

    blah blah<br><br>
    </body>
    </html>


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •