Hi I had a real estate web site and user/visitor can post their property into the database. Now What I need is After 15 days the post will be delete automatically. Please any give me the idea for doing this. "How to do delete using Date ?"

Please Help me..
Thanks
Rajeesh

You can set up a cron job to run every day (or night) and have this query. If you can't have crons, you can run this script whenever the main page is loaded.

DELETE FROM Table
WHERE datecolumn < DATE(DATE_SUB(now() , INTERVAL 15 DAY))

Ok thanks all for the kind supports to me. I did it like this and admin will check his page daily. Then It will clear the data.
Thank you Thank you......

Great :) You are welcome!

You can set up a cron job to run every day (or night) and have this query. If you can't have crons, you can run this script whenever the main page is loaded.

DELETE FROM Table
WHERE datecolumn < DATE(DATE_SUB(now() , INTERVAL 15 DAY))

Whare wxactly do i put this code?, my DB connection code looks like this:

?php

$databasename='xxxx'; // Name of the database
$tablename='xxxx'; // Name of the table
$mysqladd='xxxx'; // Address to the MySQL Server - Usually localhost but could be an IP address
$mysqluser='xxxx'; // Your MySQL UserName
$mysqlpass='xxxx'; // Your MySQL Password


//CONNECT TO MYSQL
$link=mysql_connect($mysqladd, $mysqluser, $mysqlpass) or die('Could not connect to database: ' . mysql_error());

//CONNECT TO DATABASE
mysql_select_db($databasename, $link) or die('Could not connect to table: ' . mysql_error());


$query="SELECT * FROM xxxx ORDER BY Timestamp DESC";
 
$result=mysql_query($query); 
 
$num=mysql_numrows($result); 

mysql_close(); 
  
$i=0; 
while ($i < $num) : 


?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.