PHP Include - file of the day

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harogian
    New Member
    • Jul 2007
    • 5

    PHP Include - file of the day

    Hi,

    The best description I can think of for what | am looking for is 'Content Rotator'.
    I know such scripts are available in javascript but I am hoping to find one in PHP.

    Is it possible to have a list of file names, say one one for each day/week/ or month,
    and then pass the appropriate file name to a PHP include statement?

    Clearly I am not a PHP programmer.

    Your help much appreciated.

    Thanks
    Harry
  • tscott
    New Member
    • Jul 2007
    • 22

    #2
    Hey,
    There alot of ways you could do this. One way would be to make a txt file and seperate each name with a |. Then use a script like this.
    [php]
    <?php
    //Name Rotator//
    $fileofnames = 'names.txt';
    if(file_exists( $fileofnames))
    {
    $namesfile = file_get_conten ts($fileofnames );
    $namesfile = explode('|' , $namesfile);
    $date = date('j');
    $date = $date-1;
    echo $namesfile[$date];
    }
    else
    {
    echo 'No file';
    }
    ?>
    [/php]
    That would choose names out of a file split by | so if my file's contents was
    pie|dog|mouse|c at|tyler|bah|ty ler|bah|somethi ng|etc|blah|bla h|blah| etc...
    it would show the 21st entry today.

    If you wanted to change the rotation times you can go to
    date() on php.net
    and change the current "J" in
    $date = date('j');
    to somthing like h (for hours)

    Hope this helps!
    ~Tyler
    Last edited by tscott; Jul 22 '07, 12:41 AM. Reason: Making post longer

    Comment

    • harogian
      New Member
      • Jul 2007
      • 5

      #3
      Originally posted by tscott
      Hey,
      If you wanted to change the rotation times you can go to
      date() on php.net
      and change the current "J" in
      $date = date('j');
      to somthing like h (for hours)

      Hope this helps!
      ~Tyler
      Hi,

      Thanks for your help. I checked out the date function as you suggested and after reading about arrays I got to the following.

      <div class="foo">

      <?php
      $link = array();
      $link["22"]= "foo1.htm";
      $link["23"]= "foo2.htm";
      $link["24"]= "foo3.htm";
      $link["25"]= "foo4.htm";
      $link["26"]= "foo5.htm";
      $link["27"]= "foo6.htm";
      $link["28"]= "foo7.htm";
      $today = date("d");
      include ($link["$today"]);
      ?>

      </div>

      Provided I build the array for 31 days it will load new content each day for a month.

      Alternatively I could change date("d"), to the appropriate date value, and adjust the array, so that a new page is loaded once a week, once a month, or even for each day of the year.

      Harry

      Comment

      • kovik
        Recognized Expert Top Contributor
        • Jun 2007
        • 1044

        #4
        Originally posted by harogian
        Hi,

        Thanks for your help. I checked out the date function as you suggested and after reading about arrays I got to the following.

        <div class="foo">

        <?php
        $link = array();
        $link["22"]= "foo1.htm";
        $link["23"]= "foo2.htm";
        $link["24"]= "foo3.htm";
        $link["25"]= "foo4.htm";
        $link["26"]= "foo5.htm";
        $link["27"]= "foo6.htm";
        $link["28"]= "foo7.htm";
        $today = date("d");
        include ($link["$today"]);
        ?>

        </div>

        Provided I build the array for 31 days it will load new content each day for a month.

        Alternatively I could change date("d"), to the appropriate date value, and adjust the array, so that a new page is loaded once a week, once a month, or even for each day of the year.

        Harry
        Thank you for using an array instead of a file. :-D Using a file would have been so wasteful. Though, I'd suggest you use your database, but I assume you will in the future when you want to make your updates easier.

        And so you know, it's completely unnecessary to put quotes around the $today variable, and the same goes for every number in your array.

        Comment

        • harogian
          New Member
          • Jul 2007
          • 5

          #5
          Originally posted by volectricity
          Thank you for using an array instead of a file. :-D Using a file would have been so wasteful. Though, I'd suggest you use your database, but I assume you will in the future when you want to make your updates easier.

          And so you know, it's completely unnecessary to put quotes around the $today variable, and the same goes for every number in your array.
          Hi,

          All thanks to you, this was my first time using PHP. Taking what you provided I was able to look at W3schools with more understanding, to end up with the array.

          So far as the DB is concerned I dont have one, I read somewhere earlier that you can access MS Excel thru PHP so if it becomes an issue.I can look at that or hunt for some freeware DB.

          I didnt know about the quote marks ..........just goes to prove you cant rely on 'cut n paste'.... LOL

          Maybe I should think about generating an update to an archieve list with a link for the previous day's article!....Gue ss I'll leave that awhile tho.

          Cheers
          Harry

          Comment

          • kovik
            Recognized Expert Top Contributor
            • Jun 2007
            • 1044

            #6
            Originally posted by harogian
            All thanks to you, this was my first time using PHP. Taking what you provided I was able to look at W3schools with more understanding, to end up with the array.
            Good for taking the initiative. :-D

            Originally posted by harogian
            So far as the DB is concerned I dont have one, I read somewhere earlier that you can access MS Excel thru PHP so if it becomes an issue.I can look at that or hunt for some freeware DB.
            You don't have MySQL? Are you serious? Who is your web host?

            Originally posted by harogian
            I didnt know about the quote marks ..........just goes to prove you cant rely on 'cut n paste'.... LOL
            Where did you copy and paste that from? Sounds like a website by an inexperienced programmer. Please keep in mind that there are no qualifications for programmers to meet before they are allowed to write a tutorial, so always keep a bit of skepticism and look at more resources than one.

            Originally posted by harogian
            Maybe I should think about generating an update to an archieve list with a link for the previous day's article!....Gue ss I'll leave that awhile tho.
            Databasing would solve that easily.

            Comment

            • harogian
              New Member
              • Jul 2007
              • 5

              #7
              Originally posted by volectricity
              Good for taking the initiative. :-D



              You don't have MySQL? Are you serious? Who is your web host?


              Databasing would solve that easily.
              MYSQL is available for 'free' provided I upgrade to hosting package with a bigger band width, but I wont really need it until I do something worth publishing..... ..which I havent.......ye t.

              Harry

              Comment

              • kovik
                Recognized Expert Top Contributor
                • Jun 2007
                • 1044

                #8
                Originally posted by harogian
                MYSQL is available for 'free' provided I upgrade to hosting package with a bigger band width, but I wont really need it until I do something worth publishing..... ..which I havent.......ye t.

                Harry
                What a horrible hosting company... MySQL is 'free' anyway. That's why so many of us use it. You can find hosting for free with MySQL and a usable amount of bandwidth if you take the time to look.

                Comment

                Working...