Abbeh Posted November 4, 2008 Share Posted November 4, 2008 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 More sharing options...
JasonLewis Posted November 4, 2008 Share Posted November 4, 2008 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']; Link to comment https://forums.phpfreaks.com/topic/131330-help-with-a-while-and-cron/#findComment-681950 Share on other sites More sharing options...
Abbeh Posted November 4, 2008 Author Share Posted November 4, 2008 Ah, I see it now.. thanks a lot! Link to comment https://forums.phpfreaks.com/topic/131330-help-with-a-while-and-cron/#findComment-681951 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.