MyBB Community Forums

Full Version: Add to Forum Datacache
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to add an extra array to the datacache, but I can't get it to work. has anyone else tried this before?

Here is the code I have in datacache.php
function updatenewscache()
	{
		global $db;
			$count = 0;
			$query = $this->db->query("SELECT subject,message,dateline FROM ".TABLE_PREFIX."posts WHERE fid='$fid' ORDER BY 'dateline' DESC");
			while($newsItem = $this->db->fetch_array($query))
				{
					$news[$count] = $newsItem;
					$count++;
				}
		$this->update("news", $news);
 	}

Here is the code in SDK.php
	function updateNewsCache()
	{
		$this->cache->updatenewscache();
	}
doh Toungue
Quote:WHERE fid='$fid'
Its not gettings anything since it doens't know when $fid is. Also, datacache doesn't use $this->Try:
function updatenewscache($fid)
{
global $db;
$count = 0;
$query = $db->query("SELECT subject,message,dateline FROM ".TABLE_PREFIX."posts WHERE fid='$fid' ORDER BY 'dateline' DESC");
while($newsItem = $db->fetch_array($query))
{
$news[$count] = $newsItem;
$count++;
}
$this->update("news", $news);
}

Quote:Here is the code in SDK.php
And replace that with
function NewsCache($fid)
{
$this->cache->updatenewscache($fid);
return $this->cache->read("news");
}

Now, calling
<?
require("./inc/sdk.php");
NewsCache(12);
?>
should update the stats of the number of the forum you choose by using the code in datacache.php, then read the stats it just made and output them (hopefully).

Let me know how you get on....
thanks for your help k776, but I still haven't got it working Sad

I modified the code slightly, so it dooesn't take a paramater, because in my case, I'll always want to get the posts from the same forum anyway.

Code in SDK.php:
	function updateNewsCache()
	{
		$this->cache->updatenewscache();
	}
	
	function getNewsCache()
	{
        return $this->cache->read("newscache");
 	}

Code in datacache.php:

	function updatenewscache()
	{
		global $db;
			$count = 0;
			$query = $db->query("SELECT subject,message,dateline FROM ".TABLE_PREFIX."posts WHERE fid='14' ORDER BY 'dateline' DESC");
			while($newsItem = $db->fetch_array($query))
				{
					$newscache[$count] = $newsItem;
					$count++;
				}
		$this->update("news", $newscache);

I've probally still got a silly mistake, but I called updateNewsCache() but when I call getNewsCache() it returns nothing and it's not added to the database.
thats because you try to read

return $this->cache->read("newscache");

when its only news

$this->update("news", $newscache);

and your missing a

}

at the end of you datacache code. So try this:

sdk.php
function updateNewsCache()
{
$this->cache->updatenewscache();
}

function getNewsCache()
{
return $this->cache->read("newscache");
}
datacache.php
function updatenewscache()
{
global $db;
$count = 0;
$query = $db->query("SELECT subject,message,dateline FROM ".TABLE_PREFIX."posts WHERE fid='14' ORDER BY 'dateline' DESC");
while($newsItem = $db->fetch_array($query))
{
$newscache[$count] = $newsItem;
$count++;
}
$this->update("newscache", $newscache);
}
then call it like
<?
include("./inc/sdk.php");
updateNewsCache()
getNewsCache()
?>
WooHoo at last it's working Big Grin

Thanks k776 Smile