Ristiisa Posted April 21, 2010 Share Posted April 21, 2010 Hello,im beginner with php and mysql,and i have an game,im learning on it etc,but i have problem,i want to make an energy,that it will update the energy with 5 on every 15 mins(for that im using cron jobs,i know how to use them),but i dont know how to make it i want to make it like it will add 5 energy into the energy column or smth,and the old one stays,so if it was 10,it will be 15. and if its more then 100,it will put it to 100. thanks,my english is kinda bad so yeah,i really would be happy if someone could help me and teach me it. Quote Link to comment https://forums.phpfreaks.com/topic/199268-problem-with-mysql-php-stuff/ Share on other sites More sharing options...
Ken2k7 Posted April 21, 2010 Share Posted April 21, 2010 Are you asking about MySQL or CRON? Which part are you having issues with? Writing the SQL? Creating the CRON job? Quote Link to comment https://forums.phpfreaks.com/topic/199268-problem-with-mysql-php-stuff/#findComment-1045899 Share on other sites More sharing options...
andrewgauger Posted April 21, 2010 Share Posted April 21, 2010 UPDATE table_name SET energy=energy+5 WHERE energy < 95 AND user=$userid Quote Link to comment https://forums.phpfreaks.com/topic/199268-problem-with-mysql-php-stuff/#findComment-1045900 Share on other sites More sharing options...
Ristiisa Posted April 21, 2010 Author Share Posted April 21, 2010 Are you asking about MySQL or CRON? Which part are you having issues with? Writing the SQL? Creating the CRON job? with MySQL,i know how to set up cron jobs,but problem is with the mysql thingy i tried ("UPDATE users SET energy=energy+5 WHERE energy < 95"); but it wont work,oh and it should add energy to every playes who is in users table Quote Link to comment https://forums.phpfreaks.com/topic/199268-problem-with-mysql-php-stuff/#findComment-1045905 Share on other sites More sharing options...
Ristiisa Posted April 21, 2010 Author Share Posted April 21, 2010 idk why i cant edit the text in this forums anymore,wanted to write that full scripts is <?php $username = "gsagsa"; $password = "gsagas"; $hostname = "localhost"; $dbhandle = mysql_connect($hostname, $username, $password); $selected = mysql_select_db("plapla",$dbhandle); $set=array(); ("UPDATE users SET energy=energy+5 WHERE energy < 95"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/199268-problem-with-mysql-php-stuff/#findComment-1045924 Share on other sites More sharing options...
andrewgauger Posted April 21, 2010 Share Posted April 21, 2010 take a look at http://php.net/manual/en/function.mysql-query.php You have to execute the query, mysql_query("UPDATE users SET energy=energy+5 WHERE energy < 95"); echo mysql_error(); The last line should tell you if something went wrong. This isn't the cron job, but should move you the right direction. It is likely though that there is something missing from this conversation though.... Quote Link to comment https://forums.phpfreaks.com/topic/199268-problem-with-mysql-php-stuff/#findComment-1045972 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.