3 Replies Latest reply on Apr 19, 2013 12:20 PM by Spindrift

    How can I get a PHP include to update automatically after a set date?

    Spindrift Level 1

      Hi guys,

       

      I maintain a number of website for sports athletes and on their websites I have an include for their next event - just a small PHP file with when and where the next event is.

       

      After each event I have to manually update the include to the clients' next event which is a bit of a pain and quite time-consuming.

       

      Is there any way I can set up the include script to automatically update with a different file to include after a set date?

       

      Or, even better, can I set up the include itself to display the updated content after a specific date?

       

      This is what the include contains...

       

      <img class="event" src="/images/eventPicture.png" />
      <p class="nextEvent">Location<br />
      Series<br />
      1-3 January 2013</p>
      

       

      Thank you very much and I hope to hear from you!

       

      SM

        • 1. Re: How can I get a PHP include to update automatically after a set date?
          osgood_ Level 8

          You would really need to put all the events information in a database and then use a mysql query to delete any event older than the event date in the database. When the date of the current event has expired it will be automatically replaced with the next available event date in the database.

           

           

          $deleteSQL = sprintf("DELETE FROM events WHERE eventDate < DATE_SUB(NOW(), INTERVAL 1 DAY)",

           

           

          Typically your mysql query might look like above which says DELETE from the 'events' table in the database any 'eventDate' which is older than the 'eventDate'.

           

          Have you used databases before?

           

          I'm not sure you can do it without because you need to check against a specific date.

          • 2. Re: How can I get a PHP include to update automatically after a set date?
            osgood_ Level 8

            Its easier than setting up a database...I've been dabbling. You will still need to use server-side language like php.

             

            First establish the date by adding the get date function to the page:

             

            <?php

            $date = date('d-F-Y');

            ?>

             

            Then add the below bit of php in the position where you want the 'include' to appear. (so if on the 19th of April you want event_3.php to appear:

             

            <?php

            if ($date == "19-April-2013") { ?>

            <?php include ('event_3.php')?>

            <?php } ?>

             

            This isnt economical for many event dates but if you have a few it will do as a solution.

             

            It's not great because you would need to add as below, changing the include on the date you want it to show which will replace the previous event.

             

             

            <?php

            if ($date == "19-April-2013") { ?>

            <?php include ('event_3.php')?>

            <?php } ?>

             

            <?php

            if ($date == "30-May-2013") { ?>

            <?php include ('event_4.php')?>

            <?php } ?>

             

            <?php

            if ($date == "4-June-2013") { ?>

            <?php include ('event_5.php')?>

            <?php } ?>

            • 3. Re: How can I get a PHP include to update automatically after a set date?
              Spindrift Level 1

              Thanks Osgood! That's a great help, really appreciate it