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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tonka
Forum Newbie
Posts: 1
Joined: Thu Aug 19, 2010 12:11 pm

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

Post 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?
kurbot
Forum Newbie
Posts: 18
Joined: Tue Jul 20, 2010 2:20 pm

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

Post 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
	}

Post Reply