Jump to content

[SOLVED] Help with a cron im trying to do...


seany123

Recommended Posts

okay so i am trying to make a page which updates the database for each player depending on their individual values.

 

the problem im getting is its only updating the first player who runs a page which this includes.

 

heres there code...

 

<?php
include("../lib.php");
$player = check_user($secret_key, $db);

// Values for Respected mobsters.
$maxinterest = 900000;
$interest = ($player->bank * 0.06);

//Values for normal mobsters
$maxinterest2 = 300000;
$interest2 = ($player->bank * 0.03);

if($player->rm >= 1)
{
if ($interest > $maxinterest && $player->bank + $maxinterest <= $player->maxbank)
{
$query = $db->execute("update `players` set `bank`=? where `id`=?", array($player->bank + $maxinterest, $player->id ));		
}

if ($interest > $maxinterest && $player->bank + $maxinterest >	$player->maxbank)
{
$query = $db->execute("update `players` set `money`=? where `id`=?", array($player->money + $maxinterest, $player->id ));	
}	

if ($interest <= $maxinterest && $player->bank + $interest <= $player->maxbank)
{
$query = $db->execute("update `players` set `bank`=? where `id`=?", array($player->bank + $interest, $player->id ));		
    }

if ($interest <= $maxinterest && $player->bank + $interest > $player->maxbank)
{	
    $query = $db->execute("update `players` set `money`=? where `id`=?", array($player->money + $interest, $player->id ));
}
}	

if ($player->rm <= 0)
{
if ($interest > $maxinterest2 && $player->bank + $maxinterest2 <= $player->maxbank)
{
$query = $db->execute("update `players` set `bank`=? where `id`=?", array($player->bank + $maxinterest2, $player->id ));		
}

if ($interest > $maxinterest2 && $player->bank + $maxinterest2 >	$player->maxbank)
{
$query = $db->execute("update `players` set `money`=? where `id`=?", array($player->money + $maxinterest2, $player->id ));	
}	

if ($interest <= $maxinterest2 && $player->bank + $interest2 <= $player->maxbank)
{
$query = $db->execute("update `players` set `bank`=? where `id`=?", array($player->bank + $interest2, $player->id ));		
    }

if ($interest <= $maxinterest2 && $player->bank + $interest2 > $player->maxbank)
{	
    $query = $db->execute("update `players` set `money`=? where `id`=?", array($player->money + $interest2, $player->id ));
}
}

Link to comment
https://forums.phpfreaks.com/topic/150988-solved-help-with-a-cron-im-trying-to-do/
Share on other sites

I agree.

 

When you set up a cron job you set the absolute path relative to the server, not the internet (did I explain that correctly? :P)

 

Just move the cron job outside of "public_html" or whatever folder it's in back into it's own folder that users can't access from the WWW.

 

That way you can get your cron job running safely knowing users can't access it.

here is a problem im having....

 

$query = sprintf('UPDATE players SET rm = %d WHERE id = %d', $rm, $row['id']);
   mysql_query($query) or die(mysql_error());

 

how do i change this so instead of it saying (rm =) it says (rm +)

 

can anyone help me?

okay so i have done what i can and this is what ive come up with... its giving my website a whitepage which obviously means somethings not quite right...

 

please help with what you can.

 

heres the code...

<?php
$query = "SELECT * FROM players";
$result = mysql_query($query) OR die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
   $rm = $row['rm'];
   $bank = $row['bank'];
   $maxbank = $row['maxbank'];
   $money = $row['money'];
   
// Values for Respected mobsters.
   $maxinterest = 900000;
   $interest = ($row['bank'] * 0.06);

//Calculations for Respected mobsters.
   $calc1 = $row['bank'] + $maxinterest;
   $calc2 = $row['money'] + $maxinterest;
   $calc3 = $row['bank'] + $interest;
   $calc4 = $row['money'] + $interest;
   
   
//Values for normal mobsters.
   $maxinterest2 = 300000;
   $interest2 = ($bank * 0.03);

//Calculations for Respected mobsters.
   $calc5 = $row['bank'] + $maxinterest2;
   $calc6 = $row['money'] + $maxinterest2;
   $calc7 = $row['bank'] + $interest2;
   $calc8 = $row['money'] + $interest2;


if($rm >= 1)
{
if($interest > $maxinterest && $row['bank'] + $maxinterest <= $maxbank)
{
$query = sprintf('UPDATE players SET bank = %d WHERE id = %d', $calc1, $row['id']);
mysql_query($query) or die(mysql_error());
}

if($interest > $maxinterest && $row['bank'] + $maxinterest > $maxbank)
{
$query = sprintf('UPDATE players SET money = %d WHERE id = %d', $calc2, $row['id']);
mysql_query($query) or die(mysql_error());	
}	

if($interest <= $maxinterest && $row['bank'] + $interest <= $maxbank)
{
$query = sprintf('UPDATE players SET bank = %d WHERE id = %d', $calc3, $row['id']);
mysql_query($query) or die(mysql_error());	
}

if($interest <= $maxinterest && $row['bank'] + $interest > $maxbank)
{
$query = sprintf('UPDATE players SET money = %d WHERE id = %d', $calc4, $row['id']);
mysql_query($query) or die(mysql_error());	
}
}

if($rm <= 0)	
{	
    if($interest2 > $maxinterest2 && $row['bank'] + $maxinterest2 <= $maxbank)
{
$query = sprintf('UPDATE players SET bank = %d WHERE id = %d', $calc5, $row['id']);
mysql_query($query) or die(mysql_error());
}

if($interest2 > $maxinterest2 && $row['bank'] + $maxinterest2 > $maxbank)
{
$query = sprintf('UPDATE players SET money = %d WHERE id = %d', $calc6, $row['id']);
mysql_query($query) or die(mysql_error());	
}

if($interest2 <= $maxinterest2 && $row['bank'] + $interest2 <= $maxbank)
{
$query = sprintf('UPDATE players SET bank = %d WHERE id = %d', $calc7, $row['id']);
mysql_query($query) or die(mysql_error());	
}

if($interest2 <= $maxinterest2 && $row['bank'] + $interest2 > $maxbank)
{
$query = sprintf('UPDATE players SET money = %d WHERE id = %d', $calc8, $row['id']);
mysql_query($query) or die(mysql_error());	
}
   }	
}
?>

 

EDIT: just realised i missed a }... so now its got rid of the whitepage.... now seeing if the code actaully works.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.