Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    delete data after 30 days combine scripts

    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 Code:
     <?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 Code:
    <?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

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Have you considered just keeping them separate and running them every 30 days with a cron job?
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •