Query to get threads ?
Imran Offline
Member
***
Posts: 204
Joined: Apr 2010
Post: #1
At Query to get threads ?
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


[Image: logo.png]

[Image: twitter.png]
08-18-2010 07:02 AM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: Query to get threads ?
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:
1
2
3
4
5
6
		$query = $db->query("
			SELECT tid , subject 
			FROM " .TABLE_PREFIX. threads." 
			WHERE tid=".$thread['tid']."
			ORDER BY tid
			DESC LIMIT 5");


My Blog
08-18-2010 07:36 AM
Find all posts by this user Quote this message in a reply
Imran Offline
Member
***
Posts: 204
Joined: Apr 2010
Post: #3
RE: Query to get threads ?
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 


[Image: logo.png]

[Image: twitter.png]
08-18-2010 04:42 PM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #4
RE: Query to get threads ?
You need something set for $thread['tid']

BTW, I made a mistake - it should be fid not tid.

My Blog
08-18-2010 07:38 PM
Find all posts by this user Quote this message in a reply
Imran Offline
Member
***
Posts: 204
Joined: Apr 2010
Post: #5
RE: Query to get threads ?
Thanks Yumi, it works now.
Thank You once again.

[Image: logo.png]

[Image: twitter.png]
08-18-2010 09:53 PM
Visit this user's website Find all posts by this user Quote this message in a reply
FBI Offline
Junior Member
**
Posts: 19
Joined: Apr 2010
Post: #6
RE: Query to get threads ?
IS that query resulting Thread_Prefix (1.6) also? Smile

Brand New Portal from MyBB Indonesia  to get local Bahasa (language) support.
My Unique Plugin here Smile
08-21-2010 08:36 PM
Find all posts by this user Quote this message in a reply
Imran Offline
Member
***
Posts: 204
Joined: Apr 2010
Post: #7
RE: Query to get threads ?
May be you can use by altering some code within this query.

[Image: logo.png]

[Image: twitter.png]
08-21-2010 09:01 PM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #8
RE: Query to get threads ?
I think thread prefixes are stored in a different table, so you'll need a join somewhere, depending on what you want.

My Blog
(This post was last modified: 08-21-2010 10:13 PM by ZiNgA BuRgA.)
08-21-2010 10:13 PM
Find all posts by this user Quote this message in a reply
FBI Offline
Junior Member
**
Posts: 19
Joined: Apr 2010
Post: #9
RE: Query to get threads ?
see attachments

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

PHP Code:
1
2
3
4
5
6
7
8
9
10
$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")."\";");
	}



Attached File(s) Thumbnail(s)
       

Brand New Portal from MyBB Indonesia  to get local Bahasa (language) support.
My Unique Plugin here Smile
(This post was last modified: 08-22-2010 01:07 AM by FBI.)
08-22-2010 01:06 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #10
RE: Query to get threads ?
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...

My Blog
08-22-2010 08:44 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: