Jump to content

[SOLVED] Cronjob - Updating to the same amount for each user instead of unique


Recommended Posts

Evening Everyone,

 

I have a cronjob script, it runs fine, except where the 'money' column is in the database for each user, it is updated the same amount for each user, instead of each user's unqiue amount that should be updated.

 

I'm guessing the variable I have which runs a basic math equation is stuffing it up some how, or atleast is partly responsible, It is working fine for the first user in the database, and then updating that same amount for every other user.

 

here is my cronjob script, I am commenting the variable that runs the math:

<?php // cron job
// error_reporting(E_ALL);

/** includes **/
include_once '/home/ace/public_html/conflictingforces/functions.php';
include_once '/home/ace/public_html/conflictingforces/weapons.php';
include_once '/home/ace/public_html/conflictingforces/armors.php';
include_once '/home/ace/public_html/conflictingforces/vehicles.php';


// --- variables needed for turn change --- //

/**********************/
// Player Select Variables //
/**********************/

// User Information
$all_player_accountid = all_table("id");
$all_player_username = all_table("username");
$all_player_email = all_table("email");

// Military Effectiveness
$all_player_strikeaction = all_table("strikeaction");
$all_player_defenceaction = all_table("defenceaction");
$all_player_covertaction = all_table("covertaction");

// General Statistics
$all_player_ammo = all_table("ammo");
$all_player_money = all_table("money");
$all_player_level = all_table("level");
$all_player_currentexp = all_table("currentexp");
$all_player_neededexp = all_table("neededexp");
$all_player_skilllevel = all_table("skilllevel");
$all_player_skillpoints = all_table("skillpoints");
$all_player_strength = all_table("strength");
$all_player_agility = all_table("agility");
$all_player_intelligence = all_table("intelligence");

// Talent Statistics
$all_player_talentid = all_table("talentid");
$all_player_talentname = all_table("talentname");
$all_player_talentlevel = all_table("talentlevel");
$all_player_talentpoints = all_table("talentpoints");

// Alliance Information
$all_player_allianceid = all_table("allianceid");
$all_player_alliancename = all_table("alliancename");
$all_player_allianceposition = all_table("allianceposition");

// Inventory
$all_player_weaponid = all_table("weaponid");
$all_player_armorid = all_table("armorid");
$all_player_vehicleid = all_table("vehicleid");

// Equipped Items

// Names
$equippedweaponname = select_array($weapons,$all_player_weaponid,"weapon");
$equippedarmorname = select_array($armors,$all_player_armorid,"armor");
$equippedvehiclename = select_array($vehicles,$all_player_vehicleid,"vehicle");

// ID
$equippedweaponid = select_array($weapons,$all_player_weaponid,"id");
$equippedarmorid = select_array($armors,$all_player_armorid,"id");
$equippedvehicleid = select_array($vehicles,$all_player_vehicleid,"id");

// Damage, Defence and Power
$equippedweapondamage = select_array($weapons,$all_player_weaponid,"damage");
$equippedarmordefence = select_array($armors,$all_player_armorid,"defence");
$equippedvehiclepower = select_array($vehicles,$all_player_vehicleid,"power");


/*********************** MATHS ***********************/

// Players Actions
$strike_action = (($equippedweapondamage + $all_player_strength) + $equippedvehiclepower) * 100;
$defence_action = (($equippedarmordefence + $all_player_agility) + $equippedvehiclepower) * 100;
$covert_action = ($equippedvehiclepower + $all_player_intelligence) * 100;

// Players Actions Total
$total_action = (($strike_action + $defence_action) + $covert_action);

############ PHP Freaks, it is the $players_income variable below ############

// Workout the Players Income 
$players_income = ((($strike_action * $defence_action) * $covert_action) / 100000000);

############ PHP Freaks, it is the $players_income variable above ############

$new_ammo = $all_player_ammo + 3;

// connect to the database
$rs = mysql_connect( "localhost", "ace_ACE", "****" );
$rs = mysql_select_db( "ace_cf" );

/****** Give Players their Income ******/

//**** Then do the Query ****//

####### PHP Freaks, Update query below #######

// SQL query to update the players account into the database
$sql = "UPDATE `cf_users` SET money=money+{$players_income}";

####### PHP Freaks, Update query above #######

// execute the query
$rs = mysql_query( $sql ) or die('Query:<br />' . $sql . '<br /><br />Error:<br />' . mysql_error());


/****** Give Players their Ammo ******/ 

// SQL query to update the players account into the database
$sqll = "UPDATE `cf_users` SET ammo=ammo+3";

// execute the query
$rss = mysql_query( $sqll ) or die('Query:<br />' . $sqll . '<br /><br />Error:<br />' . mysql_error());



// E-mail me the Cron Results

// e-mail the person their password
$to      = "ace@crikeygames.com.au";
$subject = "Conflicting Forces Cron Job";
// message
$message = 'The Cron Job ran at ' . date("H:i:s - M j, Y") . ''; 
// headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html;";
$headers .= " charset=iso-8859-1\r\n";
$headers .= "From: ace@crikeygames.com.au \r\n";

mail($to, $subject, $message, $headers);

?>

 

and here is the all_table() function i have made.

<?php
// Select fields from all the users tables
function all_table($select){
    $rs = mysql_connect("localhost", "ace_ACE", "*****");
    mysql_select_db("ace_cf", $rs);
    $sql = "SELECT `" . $select . "` FROM `cf_users`";
    $rs = mysql_query($sql) or die('Query:<br />' . $sql . '<br /><br />Error:<br />' . mysql_error());
    while($row = mysql_fetch_assoc($rs)){
        if(isset($row[$select])){return $row[$select];}
    }
}
?>

 

Note, the cronjob was running fine before, and then it stopped, thats why I made the neccesary changes to try and get it going once again. And also to clean up the code.

 

To summarise it all up: The $player_income variable which works out what everyones income is, is only working for the first user in the database, and then updates every other user with that same one income, instead of unique ones for each of them.

 

Any help is greatly appreciated  :)

 

Regards ACE

would a 'while' and 'do' statement work? have the 'while' run the 'do' for every user in the database, and the 'do' creates the income variable, and inserts it into the database?

I've got it working now, I changed this:

<?php
$sql = "UPDATE `cf_users` SET money=money+{$players_income}";

 

to this:

<?php
$sql = "UPDATE `cf_users` SET money=money+strikeaction*defenceaction*covertaction/100000000";

 

Regards ACE

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.