...

View Full Version : date()



Ndogg
08-29-2009, 08: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.

abduraooft
08-29-2009, 08:35 AM
[...]note that it is your responsibility to die() if necessary.
Check your query for errors.

Ndogg
08-29-2009, 08: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.

Zangeel
08-29-2009, 08: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.

Ndogg
08-29-2009, 08:52 AM
O ya :\

How do I get it to check different timezones?

Ndogg
08-29-2009, 08:56 AM
Nevermined, its 3hours after my time, thanks.

Zangeel
08-29-2009, 12:31 PM
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
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.

Fou-Lu
08-29-2009, 01: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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum