delete data after 30 days combine scripts

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
chris666uk1
Forum Newbie
Posts: 2
Joined: Thu Nov 17, 2011 10:39 am

delete data after 30 days combine scripts

Post by chris666uk1 »

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

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);
			 
             ?>
and here is the code i found to delete the data after 30 days in mysql

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());

?>
thanks for looking
Post Reply