Cron Job (Resolved)

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Cron Job (Resolved)

Post by Epiales »

Hey all... Trying to make a max turn work on the cron..... What's wrong with my code please ? :cry:

Code: Select all

<?php
include("functions.php");
connect();


$get_users = mysql_query("SELECT * FROM `stats`") or die(mysql_error());
while($user = mysql_fetch_assoc($get_users)){
    $update = mysql_query("UPDATE `stats` SET
                            `gold`=`gold`+'".$user['income']."',
                            `food`=`food`+'".$user['farming']."',
                            `turns`=`turns`+'5' WHERE `id`='".$user['id']."'") or die(mysql_error());


    $update = mysql_query("UPDATE `stats` SET
                     
                            `turns`=`turns`+'5' WHERE `id`='".$user['id']."'") or die(mysql_error());    

}

if(!isset($_SESSION['uid'])){


}else{

    
if ($stats['turns'] > $stats['maxturns']) {

    $update = mysql_query("update stats set maxturns = $stats[maxturns] WHERE id='$id'") or die ("Could not update player");
    }
}
?>
EDIT:

Well firstly I edited:

Code: Select all

$update = mysql_query("update stats set maxturns = $stats[maxturns] WHERE id='$id'") or die ("Could not update player");
To be this:

Code: Select all

$update = mysql_query("update stats set turns= $stats[maxturns] WHERE id='$id'") or die ("Could not update player");
But not go :(
Last edited by Epiales on Sun Aug 25, 2013 7:19 am, edited 1 time in total.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Cron Job

Post by Epiales »

I love talking to myslef :D :lol: :lol:

My fix so you see how I dood it :)

Code: Select all

<?php
include("functions.php");
connect();

$get_users = mysql_query("SELECT * FROM `stats`") or die(mysql_error());
while($user = mysql_fetch_assoc($get_users)){
    $update = mysql_query("UPDATE `stats` SET
                            `gold`=`gold`+'".$user['income']."',
                            `food`=`food`+'".$user['farming']."',
                            `turns`=`turns`+'5' WHERE `id`='".$user['id']."'") or die(mysql_error());
}
    
$get_stats = mysql_query("SELECT * FROM `stats`") or die(mysql_error());
while($user = mysql_fetch_assoc($get_stats)){

if ('turns' > 'maxturns');

    $update = mysql_query("update `stats` set `turns` = `maxturns` WHERE `id`='".$user['id']."'") or die(mysql_error());
    
}
?>
Last edited by Epiales on Sun Aug 25, 2013 2:37 am, edited 2 times in total.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Cron Job

Post by Epiales »

Awww man... Just when ya think you have it.. LOL...

Instead of doing the +5 it does the maxturns instead. It's not an either or GRRRR

Back I go again :cry: :cry:

And I was so excited LOL
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Cron Job

Post by Epiales »

Not sure if I"m any closer, but still no go :(

Code: Select all

<?php
session_start();
include("functions.php");

connect();

if (isset($_GET['stats']))
{

$currentturns=$stats['turns'];
            
    if ($currentturns < $stats['maxturns']) {
    
    $update = mysql_query("UPDATE `stats` SET
                            `gold`=`gold`+'".$user['income']."',
                            `food`=`food`+'".$user['farming']."',
                            `turns`=`turns`+'5' WHERE `id`='".$user['id']."'") or die(mysql_error());
                        
    } else {
    
    if ($currentturns > $stats['maxturns']) {
    
$update = mysql_query("update `stats` set `turns` = `maxturns` WHERE `id`='".$user['id']."'") or die(mysql_error());
}}}
?>
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Cron Job

Post by Epiales »

Well you have to say I'm persistent LOL. No fix yet, but I'll get there when I'm fully bald LOL. I know I'm closeity close close YAY. :shock: :shock: Time for more coffee? :roll:

Blame Halls LOL, he duh one that said to come on over and keep ya'll busy :) :) :)
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Cron Job

Post by Jackolantern »

What is the problem? Are you actually getting an error, or is it a logical error (as in, is it just not working right)?
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Cron Job

Post by hallsofvallhalla »

yep you lost me now, are you still getting an error? And yes blame me. I love all the questions and answers.
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Cron Job

Post by Epiales »

No worries... I just got through with your cron video. Question though, is how can I add under the first info you have there to add to the turns?

Code: Select all

<?php
$currenttime = time();

////////////////////static variables////////////////////
//// Everything is done in seconds////
$hptime = 30;
$healedhealth = 2;

//////////////////////////////////////////////////////

if($stats['crontime'] < 1)
{
$updateplayer="update stats set crontime='$currenttime' where id='$id'";
  mysql_query($updateplayer) or die("Could not update player");

}
else
{
$timepassed = $currenttime - $stats['crontime'];

   if($timepassed > $hptime)
   {
   $intervals = $timepassed / $hptime;
   $intervals = (int)$intervals;
   $healedhealth = $intervals * $healedhealth;
    $totalhealth = $stats['hpoints'] + $healedhealth;
   if($totalhealth > $stats['maxhp']){$totalhealth = $stats['maxhp'];}
   
   $updateplayer="update stats set crontime='$currenttime',hpoints='$totalhealth' where id='$id'";
  mysql_query($updateplayer) or die("Could not update player");
   
   }
}

?>
Basically I want to copy and paste that entire thing and use it for turns too. But I've tried and I keep getting an invalid if statement. Frustrating. So how to continue past this part?
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Cron Job

Post by Epiales »

Nevermind, I got it now LOL. And again I do it. Post it and then figure it out. LOL. Thanks for that video, was awesome.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Post Reply

Return to “Beginner Help and Support”