MyBB Hacks

Full Version: Query to get threads ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi Zinga Smile

I ran this query

PHP Code:
		$query = $db->query("
			SELECT tid , subject 
			FROM " .TABLE_PREFIX. threads." 
			ORDER BY tid
			DESC LIMIT 5");

This gives me 5 threads from complete all forums in descending order.
But the question is I want to get threads from thread's forum where thread is.. and count and show them on showthread page.

I hooked to showthread_end. Help please Zinga Frown

Are you trying to count the number of threads in a forum?

You need to put the fid of the thread in the query.  Please learn how to write SQL queries...

Probably not what you want:

PHP Code:
		$query = $db->query("
			SELECT tid , subject 
			FROM " .TABLE_PREFIX. threads." 
			WHERE tid=".$thread['tid']."
			ORDER BY tid
			DESC LIMIT 5");

Ok, this results into this error;

PHP Code:
SQL Error:
    1054 - Unknown column 't' in 'where clause'
Query:
    SELECT tid , subject FROM mybb_threads WHERE tid=t ORDER BY tid DESC LIMIT 45 

You need something set for $thread['tid']

BTW, I made a mistake - it should be fid not tid.
Thanks Yumi, it works now.
Thank You once again.
IS that query resulting Thread_Prefix (1.6) also? Smile
May be you can use by altering some code within this query.
I think thread prefixes are stored in a different table, so you'll need a join somewhere, depending on what you want.
see attachments

for this query, which one should be join (change) with thread prefix Wink

PHP Code:
$thread-trend = '';	
	$query = $db->simple_select('threads', '*', "fid='35' ORDER BY tid DESC LIMIT 10");
    while($thread-trend = $db->fetch_array($query))
	{		
		if(my_strlen($thread-trend['subject']) > 55)
		{
			$thread-trend['subject'] = my_substr($thread-trend['subject'], 0, 55) . "...";
		}
		eval("\$trend .= \"".$templates->get("portal_latest_trend")."\";");
	}

I'm not sure your code above there is valid FBI.

"$thread-trend" looks like an expression, not a variable.

Either case, I don't see a join there...
Pages: 1 2
Reference URL's