MyBB Community Forums

Full Version: View Today's Threads
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I added this code in search.php but i get MyBB error
elseif($mybb->input['action'] == "gettoday")
{
    $unviewableforums = get_unsearchable_forums();
    $cutoff = TIME_NOW - 86400;
    $search_results = $db->query("SELECT * FROM " . TABLE_PREFIX . "threads WHERE dateline>$cutoff AND  replies=0 AND fid NOT IN(" . $unviewableforums . ") ORDER BY dateline ASC"); 

	$sid = md5(uniqid(microtime(), 1));
	$searcharray = array(
		"sid" => $db->escape_string($sid),
		"uid" => $mybb->user['uid'],
		"dateline" => TIME_NOW,
		"ipaddress" => $db->escape_string($session->ipaddress),
		"threads" => '',
		"posts" => '',
		"resulttype" => "threads",
		"querycache" => $db->escape_string($query),
		"keywords" => ''
	);

	$db->insert_query("searchlog", $searcharray);
	redirect("search.php?action=results&sid=".$sid, $lang->redirect_searchresults);
}
Would be helpful if you posted the error, you know...

But I can see the mistake.
$unviewableforums = get_unsearchable_forums();
$cutoff = TIME_NOW - 86400;
$query = $db->query("SELECT * FROM " . TABLE_PREFIX . "threads WHERE dateline>$cutoff AND  replies=0 AND fid NOT IN(" . $unviewableforums . ") ORDER BY dateline ASC");
should be:
$noperms = '';
$unviewableforums = get_unsearchable_forums();
if($unviewableforums)
{
	$noperms .= " AND fid NOT IN ($unviewableforums)";
}
$inactiveforums = get_inactive_forums();
if($inactiveforums)
{
	$noperms .= " AND fid NOT IN ($inactiveforums)";
}
$cutoff = TIME_NOW - 86400;
$ordered = array('order_by' => 'dateline',
		'order_dir' => 'ASC');
$query = $db->simple_select('threads', '*', "dateline > $cutoff AND replies = 0$noperms", $ordered);
since $unviewableforums can be empty. Also added inactive forums filter and switched to simple_select.
Still getting error, screenshot below
http://i.imgur.com/9cXzpV9.png
This is the complete code that i used
elseif($mybb->input['action'] == "gettoday")
{

$noperms = '';
$unviewableforums = get_unsearchable_forums();
if($unviewableforums)
{
    $noperms .= " AND fid NOT IN ($unviewableforums)";
}
$inactiveforums = get_inactive_forums();
if($inactiveforums)
{
    $noperms .= " AND fid NOT IN ($inactiveforums)";
}
$cutoff = TIME_NOW - 86400;
$ordered = array('order_by' => 'dateline',
        'order_dir' => 'ASC');
$search_results = $db->simple_select('threads', '*', "dateline > $cutoff AND replies = 0$noperms", $ordered); 

	$sid = md5(uniqid(microtime(), 1));
	$searcharray = array(
		"sid" => $db->escape_string($sid),
		"uid" => $mybb->user['uid'],
		"dateline" => TIME_NOW,
		"ipaddress" => $db->escape_string($session->ipaddress),
		"threads" => '',
		"posts" => '',
		"resulttype" => "threads",
		"querycache" => $db->escape_string($query),
		"keywords" => ''
	);

	$db->insert_query("searchlog", $searcharray);
	redirect("search.php?action=results&sid=".$sid, $lang->redirect_searchresults);
}
Thanks for the reply
Find this line:
$search_results = $db->simple_select('threads', '*', "dateline > $cutoff AND replies = 0$noperms", $ordered);

After it do this:
$tidlist = array();
while($thread = $db->fetch_array($search_results)
{
array_push($tidlist, $thread['tid']);
}
if(!empty($tidlist))
{
$tidlist = implode($tidlist);
}
else
{
$tidlist = 0;
}

Then where you have "threads" => '' change that to "threads" => $tidlist
I did the above, but it produces the following error
http://i.imgur.com/cZJPJRZ.png
The exact code is
elseif($mybb->input['action'] == "gettoday")
{

$noperms = '';
$unviewableforums = get_unsearchable_forums();
if($unviewableforums)
{
    $noperms .= " AND fid NOT IN ($unviewableforums)";
}
$inactiveforums = get_inactive_forums();
if($inactiveforums)
{
    $noperms .= " AND fid NOT IN ($inactiveforums)";
}
$cutoff = TIME_NOW - 86400;
$ordered = array('order_by' => 'dateline',
        'order_dir' => 'ASC');
$search_results = $db->simple_select('threads', '*', "dateline > $cutoff AND replies = 0$noperms", $ordered); 
$tidlist = array();
while($thread = $db->fetch_array($search_results))
{
array_push($tidlist, $thread['tid']);
}
if(!empty($tidlist))
{
$tidlist = implode($tidlist);
}
else
{
$tidlist = 0;
} 
	$sid = md5(uniqid(microtime(), 1));
	$searcharray = array(
		"sid" => $db->escape_string($sid),
		"uid" => $mybb->user['uid'],
		"dateline" => TIME_NOW,
		"ipaddress" => $db->escape_string($session->ipaddress),
		"threads" => '',
		"posts" => '',
		"resulttype" => $tidlist,
		"querycache" => $db->escape_string($query),
		"keywords" => ''
	);

	$db->insert_query("searchlog", $searcharray);
	redirect("search.php?action=results&sid=".$sid, $lang->redirect_searchresults);
}
Pages: 1 2