I want a peice of code in a PHP to be changed automatically at a certain time

Discussion in 'PHP' started by karan265, Feb 22, 2008.

  1. #1
    Greetings Geeks,

    I wanted to know if it would be possible to write a simple PHP script if I'd like to change a certain part of one of my PHP files automatically at a specified time of my choice, this should keep repeating every 24 hours or so to ensure stability.

    I also need a countdown sort of a thing to let the user (person who views the PHP file) know as to how many hours, minutes and seconds are left for that particular code to be changed.

    I'd really appreciate some help from all you PHP expers out there! ;)

    Thanks a lot!
     
    karan265, Feb 22, 2008 IP
  2. dansgalaxy

    dansgalaxy Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This sounds very easy, what is the content you want changed?

    you could simply have a database with the content in tell it what time to start showing that piece of content and query it for the correct one to show.

    the count down would be best done with javascript, with just a count down script and have the start or end time generated by PHP...
     
    dansgalaxy, Feb 22, 2008 IP
  3. karan265

    karan265 Active Member

    Messages:
    1,691
    Likes Received:
    47
    Best Answers:
    0
    Trophy Points:
    90
    #3
    I just want 1 particular digit to be changed every 24 hours in a progression.

    Like 1, after 24 hours I want that digit changed to 2, after 24h to 3 and so on until 5 and it should go back to 1 after it reaches 5.

    Would you please elaborate more on how I could implement the above methods? :)

    Your help is greatly appreciated!

    Best Regards,
    Karan
     
    karan265, Feb 22, 2008 IP
  4. Ares

    Ares Member

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #4
    all you have to do is just save it into database , the things you need to save in database is day, value
    $day=date("m");
    and value is the value that have been saved in db !every time load it and check the date if it's different
    add to value.
     
    Ares, Feb 22, 2008 IP
  5. dansgalaxy

    dansgalaxy Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    o well thats well easy..

    All u need is one db table with:

    id | Number | change Datetime

    and have a PHP script like:

    
    <?php
    
    $result = mysql_query("SELECT * FROM table WHERE id='1'");
    $row = mysql_fetch_array($result);
    
    $date = strtotime($row['datetime']);
    
    //If last change date plus 24 hours is less than current time 
    if(($date + (60*60*24)) < date('U'))
    {
    
         if($row['number'] == '5')
         {
         mysql_query("UPDATE table SET number='1', change_datetime='{date('Y-m-d H:i:s')} WHERE id='1'");
         }
         else {
         $no = $row['number']++;
         mysql_query("UPDATE table SET number='$no', change_datetime='{date('Y-m-d H:i:s')} WHERE id='1'");
         }
    
    
    echo $no;
    }
    else {
    echo $row['number'];
    }
    
    ?>
    
    and that should do it.
    PHP:
     
    dansgalaxy, Feb 22, 2008 IP