SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: randomizing php

  1. #1
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    randomizing php

    ok...I'm not sure on how to do a search for this.
    Basically what I am looking for is a way to create one page (example.php) and throughout the course of a day or a week or just on certain days (xmas, new years, valentines, etc) to change the content of the page (for this I would use ex1.php, ex2.php, ex3.php)

    I think it would use a conditional statement- something along the lines of

    if hour=morn/afternoon/evening
    include ex2.php

    (and/or)

    if day=xxx
    include ex1.php

    I know that I've seen something similar using javascript where it would change the background depending on the hour of the day or the day of the week)

    I'm just looking to create it out of php.

    any suggestions?

    thanks

  2. #2
    SitePoint Evangelist
    Join Date
    May 2004
    Location
    Germany
    Posts
    550
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    // example.php
    $date date('G');
    if(
    $date && $date <= 6)
    {
       include_once(
    'ex1.php');
    }elseif(
    $date && $date <= 12)
    {
      include_once(
    'ex2.php');
    }elseif(
    $data 12 && $date <= 18)
    {
      include_once(
    'ex3.php');
    }elseif(
    $data 18 && $date <= 23 || $date 0)
    {
      include_once(
    'ex4.php');
    }
    This will change the page every 6 hours.
    Hope you get the idea

  3. #3
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    would this work for grabbing individual dates throughout the year so that way the pages would change according to the date:: say like march 17 (day 75/365), or july 4th (day 184/365)?

    <?php
    // example.php
    $date = date('z');
    if($date > 70 && $date <= 80)
    {
    include_once('ex1.php');
    }elseif($date > 180 && $date <= 188)
    {
    include_once('ex2.php');
    }
    ?>

  4. #4
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks fine to me...dunno how you're gonna do Easter though

  5. #5
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    great- I wasn't sure if that would work at all... I'm only just starting to understand how the codes "flow" together. (looking at all the codes and trying them out myself teaches somehow)

    As for Easter.....I'll have to figure something out...


    would I be able to combine both of those codes?

    for example::
    <?php
    // example.php
    $data = date('G');
    if($data > 0 && $data <= 6)
    {
    include_once('ex1.php');
    }elseif($data > 6 && $data <= 12)
    {
    include_once('ex2.php');
    }
    and then add in the changing hours of::

    $date = date('z');
    if($date > 70 && $date <= 80)
    {
    include_once('ex3.php');
    }elseif($date > 180 && $date <= 188)
    {
    include_once('ex4.php');
    }
    ?>

  6. #6
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Guesss I'd do something like this:
    PHP Code:
    $data date('G');
    $date date('z');
    if(
    $date 70 && $date <= 80)
    {
        include_once(
    'ex3.php');
    }elseif(
    $date 180 && $date <= 188)
    {
        include_once(
    'ex4.php');
    }elseif(
    $data && $data <= 6)
    {
        include_once(
    'ex1.php');
    }elseif(
    $data && $data <= 12)
    {
        include_once(
    'ex2.php');


  7. #7
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    great- thanks, I'll try that out...

    I figured something close to that would be the answer.


Bookmarks

Posting Permissions

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