Jump to content

[SOLVED] Delete rows, older than the current day?


spikypunker

Recommended Posts

Hey duuudes, i've got a mysql which holds an events section of my site, at the moment i log in each day and delete all entries with a date older than the current date, but yeah, i need this to be automatic really. I've set up a CRON on the server, which runs cron.php at 3 in the morning each day. In this php page i've got the following code....

 

<?
$date = date("Y-m-d");

mysql_connect ("localhost","###","###");
@mysql_select_db("###") or die ("unable to connect");

$query = "DELETE FROM events_backup WHERE 'date' < $date ;";

$result = mysql_query($query); 

mysql_close();

echo "$date ";
?>

 

I thought this would be fairly simple but alas, i've tried it on my back up table (events_backup) and it deleted all the data!

 

poo

haha my fault, simple error, should have checked!

 

<?
$date = date("Y-m-d");

mysql_connect ("localhost","maddogma_listing","mightyb00sh");
@mysql_select_db("maddogma_listings") or die ("unable to connect");

$query = "DELETE FROM events WHERE date < '$date' ;";



$result = mysql_query($query); 

mysql_close();

?>

Archived

This topic is now archived and is closed to further replies.

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