Page 1 of 1

Help! Need to list new items, then remove after 30 days

Posted: Thu Aug 19, 2010 12:19 pm
by tonka
Hi,
I'm new to PHP and programing in general. I'm a designer trying to program. Sorry if I come off as being ignorant.

I am trying to build a list of new items from a database. Each item is given a date when added. I want to call just the most recent items and have a 30 day period for which they will be listed. After 30 days they will expire and will be removed from the list.

I have no idea where to start. Any ideas?

Re: Help! Need to list new items, then remove after 30 days

Posted: Thu Aug 19, 2010 12:27 pm
by kurbot
Simply Call this on the header php file or a file that you cna include on EVERY page via include..

but this should do the trick..

Code: Select all

// How long to hold sessions
	$timeoutseconds = strtotime("+30 Days"); // 30 days in future Convert to int date
	
//this is where PHP gets the time
	$timestamp = time();
	$timeout = $timestamp-$timeoutseconds;

	$hostname = "localhost";
	$database = "";
	$username = "";
	$password = "";
	$conn = mysql_pconnect($hostname , $username , $password) or trigger_error(mysql_error(),E_USER_ERROR); 


// Select db
	mysql_select_db($database, $database );

//delete values when they leave
	$query_delete = "DELETE tablename WHERE DateFeildName<=$timeout"; // Make sure database date is in INT format
	$delete = mysql_query($query_delete, $conn) or die(mysql_error()); // Executes
	
// Check for errors
	if(!($delete)) {
		echo "Error: Delete Failed."; //Echos Error if any
	}