Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-29-2009, 07:11 AM   PM User | #1
Ndogg
Regular Coder

 
Join Date: Jun 2009
Posts: 272
Thanks: 76
Thanked 2 Times in 2 Posts
Ndogg can only hope to improve
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.
Ndogg is offline   Reply With Quote
Old 08-29-2009, 07:35 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
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.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Users who have thanked abduraooft for this post:
Ndogg (08-29-2009)
Old 08-29-2009, 07:39 AM   PM User | #3
Ndogg
Regular Coder

 
Join Date: Jun 2009
Posts: 272
Thanks: 76
Thanked 2 Times in 2 Posts
Ndogg can only hope to improve
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.
Ndogg is offline   Reply With Quote
Old 08-29-2009, 07:41 AM   PM User | #4
Zangeel
Regular Coder

 
Zangeel's Avatar
 
Join Date: Oct 2007
Location: public_html/
Posts: 638
Thanks: 17
Thanked 79 Times in 79 Posts
Zangeel will become famous soon enough
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]
Zangeel is offline   Reply With Quote
Users who have thanked Zangeel for this post:
Ndogg (08-29-2009)
Old 08-29-2009, 07:52 AM   PM User | #5
Ndogg
Regular Coder

 
Join Date: Jun 2009
Posts: 272
Thanks: 76
Thanked 2 Times in 2 Posts
Ndogg can only hope to improve
O ya :\

How do I get it to check different timezones?
Ndogg is offline   Reply With Quote
Old 08-29-2009, 07:56 AM   PM User | #6
Ndogg
Regular Coder

 
Join Date: Jun 2009
Posts: 272
Thanks: 76
Thanked 2 Times in 2 Posts
Ndogg can only hope to improve
Nevermined, its 3hours after my time, thanks.
Ndogg is offline   Reply With Quote
Old 08-29-2009, 11:31 AM   PM User | #7
Zangeel
Regular Coder

 
Zangeel's Avatar
 
Join Date: Oct 2007
Location: public_html/
Posts: 638
Thanks: 17
Thanked 79 Times in 79 Posts
Zangeel will become famous soon enough
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.
__________________
PHP Code:
$aString is_string((string)array()) ? true false// true :D 
[/CENTER]

Last edited by Zangeel; 08-29-2009 at 11:33 AM..
Zangeel is offline   Reply With Quote
Users who have thanked Zangeel for this post:
Ndogg (08-31-2009)
Old 08-29-2009, 12:03 PM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
Ndogg (08-31-2009)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:23 AM.


Advertisement
Log in to turn off these ads.