Update Automatically?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Update Automatically?

Post by Dale »

How would i get an UPDATE command to run every 24hours automatically?

Code: Select all

$sql = "UPDATE points SET points = points + 15";
^ How would i get it so that everyone in my database gets 15 points every 24 hours automatically? Is it a cron job or something, if so, how would i run that?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Theres 2 ways.

1. Use a cron job. Basically you'd write a script to do the update, then add a cron task to cron on the server. If you've got CPanel or something similar you should have a handy interface, else ask the admin.

2. Add to the index.php of the site something that updates a date to tomorrows date in a database somewhere. Each time the script runs it should check the date, if it's the current date, update all the scores and set the database date to tomorrow again.

Two problems with the second way: 1. It's a hit on the database every time the index loads, and 2: it won't update the scores if noone visits the site.
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

I might just go with option 2, and have something in the database that checks if the daily update has been made. :)
Post Reply