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
https://forums.phpfreaks.com/topic/119710-solved-removing-old-data/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.