Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: Deleting old data from mySQL

  1. #11
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    I use LEFT, INNER and RIGHT JOINs quite often, actually. I've never had much of a use for CONCAT().
    - Josh

  2. #12
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i need image upload in my login page... i need to get some idea ... help me

  3. #13
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i need help

  4. #14
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by murali1987 View Post
    i need image upload in my login page... i need to get some idea ... help me
    Please don't make off-topic posts: this is Tissy's thread, and the topic is deleting entries from a mysql database.

    If you have a different question, start your own thread. For the best response, be specific with what you want, and be sure you include:

    1) What you want to accomplish
    2) What you have already tried
    3) what problems you have encountered
    4) all relevant code, and/or a link to the page in question

    in addition, make sure you post in the appropriate forum, and research your problem beforehand. Uploading an image, for example, is a very common task and there are many tutorials to be found on the internet. You should not post asking for help until you've made a serious attempt to accomplish your goal on your own, and have run into specific problems that you can't figure out.

  5. #15
    Join Date
    Mar 2010
    Location
    Essex, UK
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Still on topic, I used the following to weed the database after 1 day (will extend to 7 days, 1 day is easier for testing).

    Code:
      $qry_del = "DELETE FROM temp WHERE timing < UNIX_TIMESTAMP(NOW() - INTERVAL 1 DAY)";
    What are people thoughts on resetting the ID.

    At the moment the ID is on sequential increament.

    However, again over a period of time, this will increase quite exponentially.

    I am thinking of at midnight, resetting the ID back to 0, in my mind and for viewing purposes this will keep the database tidy and easier to view.

    Next question therefore would be, how would i do that

    my current PHP looks like this:

    Code:
    <?php
    // connect to MySQL
    mysql_connect('server','user','password') or die("Can't connect that way!");
    @mysql_select_db('arduino') or die("Unable to select a database called 'Arduino'");
    if(ISSET($_GET['t']) && (is_numeric($_GET['t'])) && $_SERVER['REMOTE_ADDR']=='192.168.1.142'){
      // message from the Arduino
      $temp = $_GET['t'];
      $humidity = $_GET['h'];
    
      // now - 60sec x 60min x 24hrs = 1 day ago    
      $one_day_ago = time() + 60*60*24; 
    
    //  $date = time(); //echo "\n";  
    //  $date = date("Y-m-d H:i:s"); //echo "\n";
    //  $qry_add = "INSERT INTO temp(timing, temp) VALUES('$date','$temp')";
    
      $qry = "INSERT INTO temp(timing, temp, humidity) VALUES(".time().",'$temp','$humidity')";
      $qry_del = "DELETE FROM temp WHERE timing < UNIX_TIMESTAMP(NOW() - INTERVAL 1 DAY)";
      mysql_query($qry);
      mysql_query($qry_del);
    //  OPTIMIZE TABLE temp
      mysql_close();
      exit('200');
    }
    mysql_close();
    ?>
    Thank you for your continued knowledge and assistance.

    Steve

  6. #16
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    if you have an auto increment id you could do this
    Code:
    ALTER TABLE theTableInQuestion AUTO_INCREMENT=1;

  7. #17
    Join Date
    Mar 2010
    Location
    Essex, UK
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Many thanks, so this command resets the table ID back to 1, how would I then only complete this reset at midnight each day ?

  8. #18
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    might have to look into cron jobs

  9. #19
    Join Date
    May 2010
    Location
    Sacramento, CA
    Posts
    91
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Default

    CRON jobs are the best bet and very usefull!

Bookmarks

Posting Permissions

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