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."; } Link to comment https://forums.phpfreaks.com/topic/124718-solved-can-anyone-see-what-is-wrong-with-this-code/ 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(). Link to comment https://forums.phpfreaks.com/topic/124718-solved-can-anyone-see-what-is-wrong-with-this-code/#findComment-644216 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. Link to comment https://forums.phpfreaks.com/topic/124718-solved-can-anyone-see-what-is-wrong-with-this-code/#findComment-644227 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()); Link to comment https://forums.phpfreaks.com/topic/124718-solved-can-anyone-see-what-is-wrong-with-this-code/#findComment-644238 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. Link to comment https://forums.phpfreaks.com/topic/124718-solved-can-anyone-see-what-is-wrong-with-this-code/#findComment-644288 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."; } ?> Link to comment https://forums.phpfreaks.com/topic/124718-solved-can-anyone-see-what-is-wrong-with-this-code/#findComment-644293 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. Link to comment https://forums.phpfreaks.com/topic/124718-solved-can-anyone-see-what-is-wrong-with-this-code/#findComment-644295 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. Link to comment https://forums.phpfreaks.com/topic/124718-solved-can-anyone-see-what-is-wrong-with-this-code/#findComment-644404 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...... Link to comment https://forums.phpfreaks.com/topic/124718-solved-can-anyone-see-what-is-wrong-with-this-code/#findComment-644680 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.