gamesmstr Posted September 17, 2008 Share Posted September 17, 2008 Basically setting up a function to delete users inactive for over 60 days. The result grinds until it times out. There are about 4,500 records to process. if ($action == "delete"){ //Get time and find 60 day difference $ctime=time(); $daysago = $ctime - 5184000; //(60*24*60*60) $userdata = mysql_query("select * from userdb where active2<='$daysago'"); $numrecords = num_rows($userdata); echo "There are $numrecords over 60 days inactive in the database."; } Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 17, 2008 Share Posted September 17, 2008 First of all, the column 'active2' should be a DATETIME if it isn't already. If it is: #SQL SELECT * FROM userdb WHERE active2 < DATE_SUB(NOW(), INTERVAL 60 DAY) That'll be your query and it should be easy from there. Also, num_rows() is not a function, try mysql_num_rows(). Quote Link to comment Share on other sites More sharing options...
gamesmstr Posted September 17, 2008 Author Share Posted September 17, 2008 Unfortunately, I didn't create the database. The column is a INT(11) and contains a timestamp generated by the time() function. I am stuck dealing with the format it was created in. Is there any way to make my query work? I don't see anything wrong with it. Of course I am not an expert either. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted September 17, 2008 Share Posted September 17, 2008 unless you created a function called num_rows, it should probably be mysql_num_rows i'd also check my sql: $userdata = mysql_query("select * from userdb where active2<='$daysago'") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
gamesmstr Posted September 17, 2008 Author Share Posted September 17, 2008 Nope... No errors generated. Just grinds until it times out. Quote Link to comment Share on other sites More sharing options...
Stooney Posted September 17, 2008 Share Posted September 17, 2008 Not sure if you've already tried this, but if not give it a go... <?php if ($action == "delete"){ //Get time and find 60 day difference $ctime=time(); $daysago = $ctime - 5184000; //(60*24*60*60) $userdata = mysql_query("select * from userdb where active2<='$daysago'"); $numrecords = mysql_num_rows($userdata); echo "There are $numrecords over 60 days inactive in the database."; } ?> Quote Link to comment Share on other sites More sharing options...
gamesmstr Posted September 17, 2008 Author Share Posted September 17, 2008 LOL....Yes, of course I have those in there... I only posted the bit of code that was bogging down. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 18, 2008 Share Posted September 18, 2008 Oh, it's a UNIX timestamp? That's usable at least: #SQL SELECT * FROM userdb WHERE FROM_UNIXTIME(active2) < DATE_SUB(NOW(), INTERVAL 60 DAY) Try that one out. Quote Link to comment Share on other sites More sharing options...
gamesmstr Posted September 18, 2008 Author Share Posted September 18, 2008 That works... Thanks! Still don't know why mine didn't work though...... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.