View Full Version : date()
08-29-2009, 07:11 AM
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.
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.
08-29-2009, 07:35 AM
[...]note that it is your responsibility to die() if necessary.
Check your query for errors.
08-29-2009, 07:39 AM
Lol, didnt realized I didnt set how much to update shoppoints by.
This is correct, right?
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.
08-29-2009, 07:41 AM
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.
08-29-2009, 07:52 AM
O ya :\
How do I get it to check different timezones?
08-29-2009, 07:56 AM
Nevermined, its 3hours after my time, thanks.
08-29-2009, 11:31 AM
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
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.
08-29-2009, 12:03 PM
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
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.