...

View Full Version : delete data after 30 days combine scripts



chris666uk1
11-17-2011, 10:52 PM
hi i have this code running a chart script and it runs good and also i have a script that will delete the data after 30 days how would i combine them so when the page was called it checked if data was older than 30 days and delete if needed

here is my script to pulld the data


<?php

$db = @mysql_connect("localhost", "40conv", "*****") or die("Connection Error: " . mysql_error());
mysql_select_db("tempmonitor") or die("Error connecting to db.");
$oldest = strtotime( "-5 days" );
$sql = "SELECT *, UNIX_TIMESTAMP(datetime) AS datetime FROM 40conv WHERE UNIX_TIMESTAMP(datetime) > {$oldest}";
$result = mysql_query($sql);
$data = array();
while ($row = mysql_fetch_array($result)) {
$temp1[] = array($row['datetime'] * 1000, (int)$row['temp1']);;

}

$temp1 = json_encode($temp1);

?>

and here is the code i found to delete the data after 30 days in mysql



<?php

error_reporting(E_ALL ^ E_NOTICE);

header('Content-type: text/plain');

$link = mysql_connect("localhost", "40conv", "*****") or die("Database Error: " . mysql_error());
mysql_select_db("tempmonitor") or die("Error connecting to db.");
$sql_prune = "DELETE FROM 40conv WHERE DATE_SUB(CURDATE(), INTERVAL 30 DAY) > datetime";
$result = mysql_query($sql_prune) or die("Query failed: $sql_prune - " . mysql_error());

?>


thanks for looking

Spookster
11-17-2011, 11:14 PM
Have you considered just keeping them separate and running them every 30 days with a cron job?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum