Jump to content

[SOLVED] Can anyone see what is wrong with this code?


gamesmstr

Recommended Posts

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

}

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

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.

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.";
}
?>

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.