Search the Community
Showing results for tags 'clock'.
-
Hai guys, I'm programming something like a text-based game now, but I've a question.. I want to have a script running, that updates every hour (01:00, 02:00, etc.) the values of some MySQL tables. I've now something like this, but I don't know if this is the right way to do it. So do you guys have any tips to do something like this? Thanks in advance. Updater.php: if (date("i", time()) == "00") { while($x = mysql_fetch_object($dbres)) $update[$x->name] = $x->time; if(floor($update['hour']/3600) != floor(time()/3600)) { $dbres = mysql_query("SELECT GET_LOCK('hour_update',0)"); if(mysql_result($dbres,0) == 1) { $cron_pass = "secretcronpassword"; mysql_query("UPDATE `cron` SET `time`='".time()."' WHERE `name`='hour'"); include("_cron_hour.php"); mysql_query("SELECT RELEASE_LOCK('hour_update')"); } } } _cron_hour.php: if($cron_pass != "secretcronpassword") exit; $dbres = mysql_query("SELECT * FROM `aandelen`"); while($aandeel = mysql_fetch_object($dbres)) { $koersmin = rand(1,500); $koersplus = rand(1,500); mysql_query("UPDATE `aandelen` SET `koers`=`koers`+$koersplus WHERE `naam`='".$aandeel["naam"]."'"); mysql_query("UPDATE `aandelen` SET `koers`=`koers`-$koersmin WHERE `naam`='".$aandeel["naam"]."'"); } if($aandeel["koers"] < 2500) { mysql_query("UPDATE `aandelen` SET `koers`=10000 WHERE `naam`='".$aandeel["naam"]."'"); } $sql1 = mysql_query("SELECT * FROM users WHERE uurloon='1' AND familie <> 'Geen'"); if (mysql_num_rows($sql1)>0) { while($info2 = mysql_fetch_array($sql1)) { $row = mysql_fetch_assoc(mysql_query("SELECT * FROM families WHERE name='".$info2["familie"]."'")); mysql_query("UPDATE users SET cash='".($info2["cash"]+((($row["aandelen"]*200)/100)*25))."', bank='".($info2["bank"]+((($row["aandelen"]*200)/100)*75))."' WHERE login='".$info2["login"]."'"); } }