Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8

Thread: date()

  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Posts
    278
    Thanks
    78
    Thanked 2 Times in 2 Posts

    date()

    I want to have a code that updates a row every hour, I know that cron job can do this, but I never can get cron jobs to work and thought this would be easier.

    PHP Code:
    if (date("h") == 11//Hour 11
    {
    mysql_query("UPDATE `players` SET `shoppoints` WHERE $player->id");

    From this nothing happens(when I click refresh), and I did click refresh at 11.

    Im pretty sure for coding like this, you need to click refresh on that page and it wont add points when they arent on, but i know how to fix it to work good enough for me.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,864
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Quote Originally Posted by http://php.net/set_error_handler
    [...]note that it is your responsibility to die() if necessary.
    Check your query for errors.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    Ndogg (08-29-2009)

  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    278
    Thanks
    78
    Thanked 2 Times in 2 Posts
    Lol, didnt realized I didnt set how much to update shoppoints by.

    This is correct, right?

    PHP Code:
    if (date("h") == 11)
    {
    mysql_query("UPDATE `players` SET `shoppoints` = ++");

    Its kinda hard to test

    But the ++ part, I can easily change to the correct way if ++ doesnt work for this.

    I made it so, when anyone refreshes it updates the shoppoints, because I want it to set everyones points every hour.

  • #4
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    This runs off of your server's time, so if you're server is using CENTRAL US time, and you're computer is in EASTERN US time, then they wont be equal. So make sure you know the timezone your server is using.
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • Users who have thanked Zangeel for this post:

    Ndogg (08-29-2009)

  • #5
    Regular Coder
    Join Date
    Jun 2009
    Posts
    278
    Thanks
    78
    Thanked 2 Times in 2 Posts
    O ya :\

    How do I get it to check different timezones?

  • #6
    Regular Coder
    Join Date
    Jun 2009
    Posts
    278
    Thanks
    78
    Thanked 2 Times in 2 Posts
    Nevermined, its 3hours after my time, thanks.

  • #7
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    No problem, if your host allows root access, to a WHM panel, you can usually alter the timezone from there, but to check just echo the date

    PHP Code:
    <?php
        
    echo date("h:i:s");
    ?>
    Be advised that the method your using, requires you to access the page manually, and if you refresh again it will allow you to update the DB again, for an hour because date("h") will remain the same for an hour, so anyone can access the file and refresh many times and reset the db.
    Last edited by Zangeel; 08-29-2009 at 12:33 PM.
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • Users who have thanked Zangeel for this post:

    Ndogg (08-31-2009)

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Most I find will stick to GMT or UTF I think its under now.
    Don't forget that you can change you're timezone with date_[default_]timezone_set. This link will provide you with the valid timezones: http://php.ca/manual/en/timezones.php
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    Ndogg (08-31-2009)


  •  

    Posting Permissions

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