matty Posted February 21, 2007 Share Posted February 21, 2007 Hey, Ive been having some trouble with a cron job ive been trying to get working. This is what i have so. <?php $db = mysql_connect("localhost", "USER", "PASS") or Die("I cannot connect to the mysql server because: " . mysql_error()); mysql_select_db("DB") or Die("DB Error !"); $energy = mysql_query("SELECT * FROM userdb"); $energyall = mysql_fetch_array($energy); if($energyall[energy] >= 100){ $mysql_query2 = Mysql_query("Update userdb set energy=100 where dead='N'");} else{ $mysql_query2 = Mysql_query("Update userdb set energy=energy+5 where dead='N'"); } Ive tried coding it different ways. Ive tried putting the 100 into a varible and using the veriable instead. What is meant to happen is it is supposed to get all the users that arnt dead and then determine weather they have 100 energy (which is max) and therefore they cannot get more or if they have less than 100 its gives them +5 to there current energy. I have gotten it so it will do this but it will not do it again. =S All it does is when i use up some energy for i say have only 50 left once the cron has ran it will set it too 100 instead of adding 5. Any help would be appicated, im not that familiar with crons. Matt, Link to comment https://forums.phpfreaks.com/topic/39551-cron-jobs/ Share on other sites More sharing options...
paul2463 Posted February 21, 2007 Share Posted February 21, 2007 you are missing single ticks around the variable energy in this line <?php if($energyall[energy] >= 100){ ?> // it should read <?php if($energyall['energy'] >= 100){ ?> Link to comment https://forums.phpfreaks.com/topic/39551-cron-jobs/#findComment-190854 Share on other sites More sharing options...
matty Posted February 21, 2007 Author Share Posted February 21, 2007 Il give that a go and let you know how it works out. Thanks. EDIT - No that didnt make any difference =/ Link to comment https://forums.phpfreaks.com/topic/39551-cron-jobs/#findComment-190860 Share on other sites More sharing options...
paul2463 Posted February 22, 2007 Share Posted February 22, 2007 ok then add a while loop that works on each row returned <?php $db = mysql_connect("localhost", "USER", "PASS") or Die("I cannot connect to the mysql server because: " . mysql_error()); mysql_select_db("DB") or Die("DB Error !"); $energy = mysql_query("SELECT * FROM userdb"); while ($energyall = mysql_fetch_array($energy)) { $energyid = $energyall['idvalue']; //needs the correct id value calling here if($energyall['energy'] >= 100) { $mysql_query2 = mysql_query("Update userdb set energy=100 where dead='N' WHERE idvalue = '$energyid'"); } else { $mysql_query2 = mysql_query("Update userdb set energy=energy+5 where dead='N' WHERE idvalue = '$energyid'"); } } ?> Link to comment https://forums.phpfreaks.com/topic/39551-cron-jobs/#findComment-191194 Share on other sites More sharing options...
monk.e.boy Posted February 22, 2007 Share Posted February 22, 2007 My advice would be to: find php by typing "whereis php" on the command prompt Make the first line of the file #!/usr/bin/php, or see results from above Run it as a web page like you would a normal php page. Run it from the command line, "./my_php.php" Run it from the command line, "./my_php.php > out.log" check all your 'prints' are in the log file Add the above command to the cron file hope that helps monk.e.boy Link to comment https://forums.phpfreaks.com/topic/39551-cron-jobs/#findComment-191205 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.