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

}

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.