2013-02-06, 12:24 AM
Hi, anyone help. I have this piece of code where it shows 1 latest post. The process is simple, it shows 1 latest post and it creates and saved the informations. Now the problem is when I reload the page, it continues to save and save the informations. It creates a duplicate and more duplicates if I reload it again and again.
How can I make it stop saving when I reload the page? I mean, do not save if the informations are already saved and save again if there's a new/latest post?
How can I make it stop saving when I reload the page? I mean, do not save if the informations are already saved and save again if there's a new/latest post?
<?php
define("IN_MYBB", 1);
require("global.php");
global $mybb, $db;
// Fetch data
$query = $db->query("SELECT subject, username, uid, dateline, pid, tid FROM ".TABLE_PREFIX."posts WHERE visible='1' ORDER BY dateline DESC LIMIT 0,1");
// Print data
while($posts = $db->fetch_array($query))
{
$latestp = "---start---\nPost ID: ".$posts['pid']."\nLast poster: ".$posts['username']."\nDateline: ".$posts['dateline']."\nLast poster UID: ".$posts['uid']."\nThread ID: ".$posts['tid']."\nPost ID: ".$posts['pid']."\nSubject: ".$posts['subject']."\n---end---\n";
$open = fopen("lastpostlog.txt", "a");
fwrite($open, $latestp);
fclose($open);
echo $latestp;
}
?>