Here's what I have for that code:
PHP Code:
if (isset($templatecache[$templatename])) {
$template=$templatecache[$templatename];
} else {
$gettemp=$DB_site->query_first("SELECT template FROM template WHERE title='".addslashes($templatename)."' AND (templatesetid=-1 OR templatesetid=" . intval($templatesetid). ") ORDER BY templatesetid DESC LIMIT 1");
$template=$gettemp[template];
$templatecache[$templatename]=$template;
}