Page 1 of 1

Cron Job (Resolved)

Posted: Sun Aug 25, 2013 1:31 am
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 :(

Re: Cron Job

Posted: Sun Aug 25, 2013 2:22 am
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());
    
}
?>

Re: Cron Job

Posted: Sun Aug 25, 2013 2:24 am
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

Re: Cron Job

Posted: Sun Aug 25, 2013 3:10 am
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());
}}}
?>

Re: Cron Job

Posted: Sun Aug 25, 2013 3:38 am
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 :) :) :)

Re: Cron Job

Posted: Sun Aug 25, 2013 4:53 am
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)?

Re: Cron Job

Posted: Sun Aug 25, 2013 6:56 am
by hallsofvallhalla
yep you lost me now, are you still getting an error? And yes blame me. I love all the questions and answers.

Re: Cron Job

Posted: Sun Aug 25, 2013 7:12 am
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?

Re: Cron Job

Posted: Sun Aug 25, 2013 7:19 am
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.