Jump to content

Script to delete files and database entries based on date


sac0o01

Recommended Posts

Maybe some of the great coders here can help this noob out.

So here is what I have so far:

 

//set age criteria for deletion
$age = 60;

//get current date
$datenow  = date("Y-m-d");

//set the range we want to delete
$delete_range = $datenow - $age;

//get old user_id from users table
$oldusers_users = mysql_query ("SELECT user_id FROM users WHERE lastvisit < $delete_range ");

//get user_id from images table that correspond to users table 
$oldusers_images = mysql_query ("SELECT user_id FROM images WHERE $oldusers_users=user_id.images ");

//find folders that correspond to the usernames and delete
$oldusers_files = mysql_query ("SELECT username FROM users WHERE lastvisit < $delete_range ");
//print out username
//$result = mysql_($oldusers_files);
$foldername = mysql_result($oldusers_files, 0); 

$sigspath = "sigs/";
unlink($sigspath . $foldername . ".gif/index.php");
rmdir($sigspath . $foldername . ".gif");
//now delete user_id's from database
mysql_query("DELETE * FROM users WHERE user_id=$oldusers_users");
mysql_query("DELETE * FROM images WHERE user_id=$oldusers_images");
unset($oldusers_users, $oldusers_images, $oldusers_files, $foldername, $sigspath );
mysql_close($link);

 

Right now it is only returning the first entry, not the entire list that meets the criteria.  It does delete that one file though but does not remover the rows from the database.

 

I am sure the database stuff is jacked up I am really new to that part.  What am I doing wrong here or is there a better way to do this perhaps

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.