I need a little php script

Discussion in 'PHP' started by moneydude, May 26, 2009.

  1. #1
    I need really short script that will work this way;

    I want to add 5 names and after 24h it will display another name ( every day another name :p ).

    Example, if I will add:

    Name1
    Name2
    Name3

    and day1 it will show name1, after 24h(day2) it will show Name2 and after another 24h it will show Name3 ;)

    Thanks a lot !
     
    moneydude, May 26, 2009 IP
  2. yoes_san

    yoes_san Peon

    Messages:
    443
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    something like

    <?php
    
    if(date("D") == "Mon"){
    echo "name1";
    }elseif(date("D") == "Tue"){
    echo "name2";
    }elseif(date("D") == "Wed"){
    echo "name3";
    }
    //and so on until Sun
    
    ?>
    Code (markup):
    should do
     
    yoes_san, May 26, 2009 IP
  3. grabus

    grabus Peon

    Messages:
    87
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    grabus, May 26, 2009 IP
  4. -[z]-

    -[z]- Active Member

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #4
    TheFileThatChosesTheName.php
    
    <?
    $name_file = file("names.txt");
    $last_name_position = file("temp.txt");
    
    //If today (the 15th) is not the same as yesterday or last time script was 
    //loaded print the next name in the list in the file names.txt
    if (date("j") != $last_name_position[1]) {
    
    //----------This should prevent errors about array out of bounds----------//
    //If the following produces errors change the -1 to 0
    //If it is still producing errors remove this section
    if ($new_position => count($name_file)) {
    $fp = fopen($last_name_position, 'w');
    fwrite($fp, "-1".'
    '.date("j"));
    fclose($fp);
    }
    $last_name_position = file("temp.txt");
    //-------The above should prevent errors about array out of bounds-------//
    
    //Set today's name position
    $new_position = $last_name_position[0] +1;
    
    //Write to file today's new name position and the current date (the 15th)
    $fp = fopen($last_name_position, 'w');
    fwrite($fp, $new_position.'
    '.date("j"));
    fclose($fp);
    
    //Print the name to screen
    echo($name_file[$new_position]);
    }
    ?>
    
    PHP:
    names.txt
    
    name1
    name2
    name3
    name4
    name5
    ...
    
    Code (markup):
    temp.txt
    
    0
    15
    
    Code (markup):
    The zero in the temp.txt file means the beginning of the list.
    Please note where the new lines are, Very Important.



    Or something similar to the above... It will not assign a certain name to a certain day as yoes_san's code does. This code will go through the entire names.txt file, each time the file is called or loaded it will print the next name in the list. Please note I haven't tested the code but I think it should work.
     
    -[z]-, May 27, 2009 IP