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

Link to comment
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.

 

 

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?

Link to comment
Share on other sites

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.