Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9027119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:40:55+00:00 2026-06-16T06:40:55+00:00

I have a php file that I run via cron. For testing I’ve set

  • 0

I have a php file that I run via cron. For testing I’ve set it to run every hour, but normally it will run once a day. What I want is to make it so that if the player has the autotechrefinery field set to 1, then they should have their population pulled from the table, how much money, research supplies, and technology they have.

From there, what I want is to deduct 500 researchsupplies, add 50 technology, and deduct 10% of population from money. All of this seems to be working when I run the file manually, but when I let it run automatically via cron, there is something that isn’t working that as a result it sets technology to 50, researchsupplies to -500 and money to 0.

$refCheck = mysql_query("SELECT * FROM players WHERE autotechrefinery='1'");
while($rC = mysql_fetch_array($refCheck)) {

$nation = $rC['nation'];
$pop = $rC['population'];
$rsupplies = $rC['researchsupplies'];
$cash = $rC['money'];
$tech = $rC['technology'];

$newtech = $tech+50;
$newmoney = $cash-($pop*.1);
$newsupplies = $rsupplies-500;

mysql_query("UPDATE players SET money='$newmoney', technology='$newtech', researchsupplies='$newsupplies', techbought='1' WHERE autotechrefinery='1'"); }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T06:40:56+00:00Added an answer on June 16, 2026 at 6:40 am

    The bug in your code is: the UPDATE will always update all entries. So all entries get the value assigned of the last pass of your loop.

    To fix the code you need some ID to identify the row and use it in the update:

    $refCheck = mysql_query("SELECT * FROM players WHERE autotechrefinery='1'");
    while($rC = mysql_fetch_array($refCheck)) {   
      $ID = $rC['id'];
      $nation = $rC['nation'];
      $pop = $rC['population'];
      $rsupplies = $rC['researchsupplies'];
      $cash = $rC['money'];
      $tech = $rC['technology'];
    
      $newtech = $tech+50;
      $newmoney = $cash-($pop*.1);
      $newsupplies = $rsupplies-500;
    
      mysql_query("UPDATE players SET money='$newmoney', technology='$newtech', researchsupplies='$newsupplies', techbought='1' WHERE id="$ID');
    }
    

    You didn’t ask for improvements but you could achieve the same result with one SQL statement:

    UPDATE players set money=money - population * .1, technology = technology + 50, researchsupplies = researchsupplies - 500;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a php file that will run an event after five minutes have
I have a PHP script, run via cron, that iterates through a list of
I have a php script that i run via command line like php file.php
I have a cron job that needs to include this file: require '../includes/common.php'; however,
I have an index.php file that loads other php files via this javascript/ajax code:
I have a PHP file that is needed to be run from the command
Firstly, I have built PHP scripts that run as a cron job when I
I have a PHP file that invokes another PHP file via curl. I am
On my php host, I have a script that is run by a cron
I have a PHP file that contains a large array (about 90KB). I'm considering

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.