i'm trying to display the last threads in forumhome.
does anyone knows how can I set time/date limit in the query so it will get the latest threads in X Days \ Hours. If i dont do that it will look in the entire table that will cause an overload in the server.
PHP Code:
$forumperms = array();
foreach($forumcache AS $forum) {
$forumperms["$forum[forumid]"] = fetch_permissions($forum['forumid']);
// ## HIDE FORUMS WITHOUT THE CANVIEW OR CANVIEWOTHERS PERMISSION ##
if (!($forumperms["$forum[forumid]"] & CANVIEW) || !($forumperms["$forum[forumid]"] & CANVIEWOTHERS)) {
$limitfids .= ','.$forum['forumid'];
}
}
unset($forum);
if ($vboptions['threadpreview'] > 0) {
$previewfield = ', post.pagetext AS preview';
$previewjoin = 'LEFT JOIN '.TABLE_PREFIX.'post AS post ON(post.postid = thread.firstpostid)';
}
$getthreads = $DB_site->query("
## GET LATEST THREADS ##
SELECT pagetext, thread.*,thread.iconid AS threadiconid $previewfield
FROM ".TABLE_PREFIX."thread AS thread
LEFT JOIN ".TABLE_PREFIX."deletionlog AS deletionlog ON(thread.threadid = deletionlog.primaryid AND type = 'thread')
$previewjoin
WHERE open = '1'
AND forumid NOT IN (0$limitfids)
AND thread.visible = '1'
AND deletionlog.primaryid IS NULL
ORDER BY lastpost DESC LIMIT 5");
while($thread = $DB_site->fetch_array($getthreads)) {
$threads = true;
$thread['message'] = parse_bbcode2($thread['pagetext'], 0, 0, 1, 1);
if (strlen($thread['message']) > 500)
{
$tobecontinued = '... <a href="' . $vboptions[bburl] . '/showthread.php?t=' . $thread[threadid] . '">???? ?????</a>';
$thread['message'] = substr($thread['message'], 0, 500).$tobecontinued;}
$thread['title'] = fetch_censored_text(fetch_trimmed_title(unhtmlspecialchars($thread['title']), 68));
$thread['date'] = vbdate($vboptions['dateformat'], $thread['lastpost'], 1);
$thread['time'] = vbdate($vboptions['timeformat'], $thread['lastpost']);
$thread['replycount'] = vb_number_format($thread['replycount']);
// show goto new post
$show['firstnew'] = false;
$bbforumview = fetch_bbarray_cookie('forum_view', $thread['forumid']);
if ($bbforumview > $bbuserinfo['lastvisit']) {
$lastread = $bbforumview;
} else {
$lastread = $bbuserinfo['lastvisit'];
}
if ($thread['lastpost'] > $lastread) {
$threadview = fetch_bbarray_cookie('thread_lastview', $thread['threadid']);
if ($thread['lastpost'] > $threadview) {
$show['firstnew'] = true;
$show['icon'] = false;
}
}
exec_switch_bg();
eval("\$threadbits .= \"".fetch_template('forumhome_latestthreadbit')."\";");
}
if ($threads) {
$show['latestthreads'] = true;
}
// memory saving
unset($thread, $threads);
$DB_site->free_result($getthreads);
thanks in advance