delete data after 30 days combine scripts
Posted: Thu Nov 17, 2011 3:48 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
and here is the code i found to delete the data after 30 days in mysql
thanks for looking
here is my script to pulld the data
Code: Select all
<?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);
?>Code: Select all
<?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());
?>