Jump to content

Cron refreshing for a full minute


Sinikka

Recommended Posts

I have a cron setup through cronjobs to restock shops at certain times through out the day and the cron works correctly with one exception. For about a minute from the time the cron executes it seems to be refreshing continually when it's only supposed to refresh the stock one time. If anyone could possibly help me with why it's doing this I'd appreciate it very much.

 

<?php

#!/usr/bin/php


$dbh=mysql_connect ("localhost", "DBNAME", "DBPW") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("DBNAME");

$findItems = mysql_query("SELECT * FROM shop_items2 WHERE game = '1'");
while ($getItems = mysql_fetch_array($findItems))
{
$id = $getItems[id];
$getItems[max_stock] = round($getItems[max_stock] / 3);
$rand[$id] = rand(0,$getItems[max_stock]);
}

foreach ($rand as $id => $val)
{
    $sql2="UPDATE `shop_items2` SET cur_stock=ROUND((max_stock/3) * RAND() ) WHERE game = '1' ";
    mysql_query($sql2);
}

echo $sql2;


?>

Link to comment
https://forums.phpfreaks.com/topic/136327-cron-refreshing-for-a-full-minute/
Share on other sites

I think I see the problem.  In your UPDATE query, you don't actually use an ID in your WHERE clause so it ends up updating EVERYTHING on each pass of the foreach loop. =/

 

Also, you need to put the shebang line as the first line in the file for it to do anything I think.

I think I see the problem.  In your UPDATE query, you don't actually use an ID in your WHERE clause so it ends up updating EVERYTHING on each pass of the foreach loop. =/

 

Also, you need to put the shebang line as the first line in the file for it to do anything I think.

 

 

Thank you, I'll try adding in a query for each shop and see if that stops the continual updating. What do you mean by the shebang line?

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.