FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum » How To » How to get messages from a particular forum
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
How to get messages from a particular forum [message #30591] Fri, 03 March 2006 14:13 Go to next message
acollins22 is currently offline  acollins22   United Kingdom
Messages: 11
Registered: June 2005
Location: Leicestershire, England
Karma: 0
Junior Member
Hi Folks,

I'd like to get the last 20 posts from one articular forum to display on a page.

Having read the various threads here I decided to go the FUDapi way. As there isn't a function to do exactl what I want I'd like to write on based on fud_fetch_recent_msg and that's where I come unglued.

fud_fetch_recent_msg reads as...
function fud_fetch_recent_msg($arg=1)
{
	$range = time() - 86400 * (float) $arg;
	return _fud_msg_multi(0, "SELECT id FROM ".$GLOBALS['DBHOST_TBL_PREFIX']."msg WHERE apr=1 AND post_stamp > ".$range);
}


so I figure I should change arg to be the forum number I want and change the WHERE clause to match the forum_id to $arg and that's the rub, I don't know what the row title is for the forum_id.

What I have is...
function fetch_forum_msg($arg=5)
{
	return _fud_msg_multi(0, "SELECT id FROM ".$GLOBALS['DBHOST_TBL_PREFIX']."msg WHERE apr=1 AND forum_id = ".$arg);
}


Am I on the right track? If so could you please point me at the correct clause syntax?


Thanks.

Andy.
Re: How to get messages from a particular forum [message #30623 is a reply to message #30591] Sun, 05 March 2006 16:55 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
Close but not quite, the message table does not have a forum_id column, the thread table does. So you need to join the two tables together by thread_id and then your query will work.

FUDforum Core Developer
Re: How to get messages from a particular forum [message #30638 is a reply to message #30591] Mon, 06 March 2006 16:01 Go to previous messageGo to next message
acollins22 is currently offline  acollins22   United Kingdom
Messages: 11
Registered: June 2005
Location: Leicestershire, England
Karma: 0
Junior Member
Hi Ilia,

Thanks for the reply. I've been having a look at this but I'm a bit of a newbie here.

As a QnD hack I've tried this code in my SQL console.
SELECT fud26_msg.id as id
	FROM fud26_thread, fud26_msg
	WHERE fud26_msg.id = fud26_thread.id AND fud26_msg.apr = 1 AND fud26_thread.forum_id = 2
	ORDER BY id DESC


That works fine but if I put that code into my version of fetch_forum_msg it's no-go.

function fetch_forum_msg($arg=5)
{
$range = time() - 86400 * (float) $arg;

return _fud_msg_multi(0, "SELECT fud26_msg.id as id
	FROM fud26_thread, fud26_msg
	WHERE fud26_msg.id = fud26_thread.id AND fud26_msg.apr = 1 AND fud26_thread.forum_id = 2
	ORDER BY id DESC");
}

(I know this is a hack but I'm just trying to prove a point at first.)

If I look at _fud_msg_multi it's already doing a join, can I use that.

Sorry to be a bit vague here but I'm really out of my depth (though I'm learning fast). Please could you be more specific for me?


Thanks.

Andy.
Re: How to get messages from a particular forum [message #30642 is a reply to message #30638] Mon, 06 March 2006 18:14 Go to previous message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
In the ORDER BY id DESC you need to identify the name of the table you are referencing the id field from.

FUDforum Core Developer
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: login name
Next Topic: PHP includes
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 23:19:46 GMT 2024

Total time taken to generate the page: 0.02812 seconds