Well, unfortunately MySQL data does not have an expiring cache. You would have to set one of your fields to store a timestamp. From there, whenever you want to put/post/get your data, check the timestamp to make sure it's not more than 7 days old. This will simulate data being no more than 7 days old.
For example, let's say you have a column named 'timestamp' which stored UNIX time, and you want to retrieve records younger than 7 days. For this, you'll need to store time using time() instead of date(). You can always convert it later.
PHP Code:
$seven_days = strtotime("-7 day");
$query = mysql_query("SELECT * FROM temp WHERE timing > $seven_days") or die(mysql_error());
And you would modify your current code to this:
PHP 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'];
$date = time(); //echo "\n";
$qry = "INSERT INTO temp(timing, temp) VALUES('$date','$temp')";
mysql_query($qry);
mysql_close();
exit('200');
}
mysql_close();
?>
Bookmarks