Jump to content

[SOLVED] Removing Old Data


monkeypaw201

Recommended Posts

So, I have a database and I would like to "flush" it every 15 minutes and remove any data older than 15 minutes.

 

The code I am using right now removes everything even If its just a few minutes old. The column `last_update` is formatted using time()

 

<?php
#Connect to database
$con = mysql_connect("localhost","user","pass");
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }

#Select database
mysql_select_db("database", $con);

#Declare Flush Timestamp
$timestamp = time();

#Cycle Through and remove excess flights
$flush = mysql_query("SELECT * FROM `active_flights`");
while($row_flush = mysql_fetch_array($flush))
{

#Generate Timeout Timestamp
$timeflush = $row_flush['last_update'] + 900;

if($timeflush > $timestamp)
{

	mysql_query("DELETE FROM `active_flights` WHERE `id` = '$row_flush[id]' LIMIT 1");

	mysql_query("DELETE FROM `active_flights_archive` WHERE `archive_id` = '$row_flush[archive_id]'");

}

}

 

Any suggestions?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.