MyBB Community Forums

Full Version: need help with this sql query?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I don't understand why this query doesn't work. It suppose to always fetch the latest 10 threads but instead is only shows the ones that were posted in the last 24 hours.

How to make it so that it will just show 10 threads starting at the top with the most recent one?

$max = 10;
	    $query = $db->query("
        SELECT t.tid, t.fid, t.subject, t.dateline, 
       t.lastposter, t.lastposteruid, f.name,
       u.usergroup, u.displaygroup, p.displaystyle AS threadprefix, l.displaygroup AS ldisplaygroup, l.usergroup AS lusergroup
        FROM ".TABLE_PREFIX."threads t
        LEFT JOIN ".TABLE_PREFIX."threadprefixes p ON (p.pid=t.prefix)
        INNER JOIN ".TABLE_PREFIX."forums f
       ON (f.fid = t.fid)
        LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
        LEFT JOIN ".TABLE_PREFIX."users l ON (l.uid=t.lastposteruid)
        WHERE $unviewwhere t.visible='1' AND t.closed NOT LIKE 'moved|%'
        ORDER BY t.dateline DESC LIMIT $max");

I tried adding:

$datecut = TIME_NOW-(172800);
WHERE t.dateline >='".$datecut."' $unviewwhere AND t.visible='1' AND t.closed NOT LIKE 'moved|%'

But makes no difference !

I have a forum that can only be viewed by admin how to make it not to fetch threads from the forum that is hidden from guest view?
I'm not seeing where $unviewablewhere is defined. Also use LEFT JOIN instead of INNER JOIN. You should also order by t.lastpost because that represents the last post time. The field dateline refers to the date the thread was posted.

As to the permission question you can use the get_unsearchable_forums function. This returns a CSV list of forums the user can't view / search.
$unviewableforums = get_unsearchable_forums();
$unviewable = " AND t.fid NOT IN(" . $unviewableforums . ") ";
Thanks buddy very much really appreciate this. I get an error!

"Fatal error: Call to undefined function get_unsearchable_forums()"
You probably need to do
require_once "inc/functions_search.php";
LOL yeah that fixed the problem thanks