Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks
Author Message
borat
Hangin' Around


Joined: Aug 05, 2005
Posts: 29

PostPosted: Sat Aug 06, 2005 2:00 am Reply with quote

Hi

if you have different forum categories and you want a block to only show posts from one forum category how would you do it? Here is the code to my forums block:

Code:


<?php

if (eregi("block-Forums.php", $_SERVER['PHP_SELF'])) {
    Header("Location: index.php");
    die();
}

global $prefix, $db, $sitename;

$result = $db->sql_query("SELECT forum_id, topic_id, topic_title FROM ".$prefix."_bbtopics ORDER BY topic_last_post_id DESC LIMIT 20");
$content = "<br>";
while ($row = $db->sql_fetchrow($result)) {
    $forum_id = intval($row['forum_id']);
    $topic_id = intval($row['topic_id']);
    $topic_title = $row['topic_title'];
    $title1 = substr("$topic_title", 0,18);
    $row2 = $db->sql_fetchrow($db->sql_query("SELECT auth_view, auth_read FROM ".$prefix."_bbforums WHERE forum_id='$forum_id'"));
    $auth_view = intval($row2['auth_view']);
    $auth_read = intval($row2['auth_read']);
    if (($auth_view < 2) OR ($auth_read < 2)) {
        $content .= "<a href=\"modules.php?name=Forums&amp;file=viewtopic&amp;t=$topic_id\">$title1...</a><br>";
    }
}



?>


e.g. if I want to show posts from category 7 like at this url: Only registered users can see links on this board! Get registered or login!

what would I have to adjust in the block code?
 
View user's profile Send private message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 17077

PostPosted: Sat Aug 06, 2005 6:04 am Reply with quote

Only registered users can see links on this board! Get registered or login!
 
View user's profile Send private message
borat
PostPosted: Sat Aug 06, 2005 10:43 am Reply with quote

I feel like such a fool now (not doing a search first), thanks so much Raven!
 
Raven
PostPosted: Sat Aug 06, 2005 10:47 am Reply with quote

Cheers RavensScripts
 
borat
PostPosted: Sun Aug 07, 2005 4:07 am Reply with quote

Hi

I've taken a look at that post and I'm a bit stumped. I can't get it to work. From the code I supplied above how do I specifiy to pull posts from more than one forum_id?

e.g. if I only want to show posts from forum_id 2, 3 and 4?
I would appreciate any help from anybody who can help me change the code above.

again I apologize if there is an obvious solution but I just can't get it to work Embarassed
 
borat
PostPosted: Sun Aug 07, 2005 5:13 am Reply with quote

hi

I managed to return the results from one forum id by doing adding a WHERE statement like this:

Code:
SELECT forum_id, topic_id, topic_title FROM ".$prefix."_bbtopics WHERE forum_id=1 ORDER BY topic_last_post_id DESC LIMIT 20


this works.
however i need to return specific forum id's such as forum id 1, 2 and 3. how do i return more than one forum id?
 
Raven
PostPosted: Sun Aug 07, 2005 8:29 am Reply with quote

Code:
WHERE forum_id IN(1,3,23)

Change the numbers to whatever numbers you need.
 
borat
PostPosted: Sun Aug 07, 2005 9:56 am Reply with quote

aah yes that works.

thanks so much for your help. Much appreciated.
 
borat
PostPosted: Sun Aug 07, 2005 12:07 pm Reply with quote

Just another question, is there an opposite of using IN e.g. if I wanted to exclude only one forum_id number what could I use instead of IN?

e.g. show all forum_id's expect for forum_id number 3?

is there a way to do that?
 
Raven
PostPosted: Sun Aug 07, 2005 2:00 pm Reply with quote

!IN()
 
borat
PostPosted: Mon Aug 08, 2005 4:01 am Reply with quote

thanks, I also tried NOT IN and that also works!

sorry for being a pest but everyday is a learning experience for me. Thanks again for your help.
 
Raven
PostPosted: Mon Aug 08, 2005 4:11 am Reply with quote

! = NOT Smile RavensScripts
 
CodyG
Life Cycles Becoming CPU Cycles


Joined: Jan 02, 2003
Posts: 712
Location: Vancouver Island

PostPosted: Mon Aug 08, 2005 11:48 am Reply with quote

Quote:
WHERE forum_id IN(1,3,23)



I tried "where t.forum_id=f.forum_id IN(34,35,36)" in the following ... but it gives me blank tables. Can you help me fix it Raven, please?

Code:
$result = sql_query( "SELECT t.topic_id, f.forum_name, f.forum_id, t.topic_last_post_id, t.topic_title, t.topic_poster, t.topic_views, t.topic_replies, t.topic_moved_id FROM ".$prefix."_bbtopics t, ".$prefix."_bbforums f where t.forum_id=f.forum_id IN(34,35,36)ORDER BY topic_last_post_id DESC", $dbi );

while( list( $topic_id, $forum_name, $forum_id, $topic_last_post_id, $topic_title, $topic_poster, $topic_views, $topic_replies, $topic_moved_id ) = sql_fetch_row( $result, $dbi ) )

_________________
"We want to see if life is ubiquitous." D.Goldin 
View user's profile Send private message
Raven
PostPosted: Mon Aug 08, 2005 12:42 pm Reply with quote

Code:
where f.forum_id IN(34,35,36) AND t.forum_id=f.forum_id
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©