Jump to content

Help with a 'while' and Cron?


Abbeh

Recommended Posts

Okay, I have a cron file which updates member accounts among other things overnight.  For some reason, it's only expiring upgraded accounts one at a time, which poses a real problem if 6 accounts need to be expired - it takes 6 nights!  Can anyone spot anything wrong with this coding? [i've checked that all the names match the table, and no MySQL errors appear]

 



//REMOVE EXPIRED UPGRADES
$result = mysql_query("SELECT mid FROM members WHERE daysleft<'1'")
or die ('cannot remove upgrade and reset daysleft 2');

while ($row = mysql_fetch_array($result))
{
$mid = $row['mid'];
$result = mysql_query("SELECT sid FROM stables WHERE mid='$mid'")
or die ('cannot get barn id');

$row = mysql_fetch_array($result);
$stables = $row['sid'];

mysql_query("UPDATE horses SET stable=1 WHERE stable='$stables'")
or die ('cannot remove horses from deleted barn');

mysql_query("DELETE FROM stables WHERE mid='$mid'")
or die ('cannot delete members barn for expired upgrade');

mysql_query("UPDATE members SET daysleft=365, type=1, horselimit=10, prefix='', avatar='', fullpage=0 WHERE mid='$mid'")
or die ('cannot update member upgrade status');
}

 

Does anyone have any ideas?

Link to comment
https://forums.phpfreaks.com/topic/131330-help-with-a-while-and-cron/
Share on other sites

You are resetting the $row and $result variable inside the while loop. Try changing this:

 

$result = mysql_query("SELECT sid FROM stables WHERE mid='$mid'")
   or die ('cannot get barn id');
   
   $row = mysql_fetch_array($result);
   $stables = $row['sid'];

 

To this:

 

$sresult = mysql_query("SELECT sid FROM stables WHERE mid='$mid'")
   or die ('cannot get barn id');
   
   $srow = mysql_fetch_array($sresult);
   $stables = $srow['sid'];

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.