Author |
Message |
borat
Hangin' Around

Joined: Aug 05, 2005
Posts: 29
|
Posted:
Sat Aug 06, 2005 2:00 am |
|
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&file=viewtopic&t=$topic_id\">$title1...</a><br>";
}
}
?>
|
e.g. if I want to show posts from category 7 like at this url:
http://www.ravenphpscripts.com/forumsindex-c-7.html
what would I have to adjust in the block code? |
|
|
|
 |
Raven
Site Admin/Owner

Joined: Aug 27, 2002
Posts: 17088
|
Posted:
Sat Aug 06, 2005 6:04 am |
|
|
|
 |
borat

|
Posted:
Sat Aug 06, 2005 10:43 am |
|
I feel like such a fool now (not doing a search first), thanks so much Raven! |
|
|
|
 |
Raven

|
Posted:
Sat Aug 06, 2005 10:47 am |
|
|
|
 |
borat

|
Posted:
Sun Aug 07, 2005 4:07 am |
|
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  |
|
|
|
 |
borat

|
Posted:
Sun Aug 07, 2005 5:13 am |
|
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

|
Posted:
Sun Aug 07, 2005 8:29 am |
|
Code:WHERE forum_id IN(1,3,23)
|
Change the numbers to whatever numbers you need. |
|
|
|
 |
borat

|
Posted:
Sun Aug 07, 2005 9:56 am |
|
aah yes that works.
thanks so much for your help. Much appreciated. |
|
|
|
 |
borat

|
Posted:
Sun Aug 07, 2005 12:07 pm |
|
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

|
Posted:
Sun Aug 07, 2005 2:00 pm |
|
|
|
 |
borat

|
Posted:
Mon Aug 08, 2005 4:01 am |
|
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

|
Posted:
Mon Aug 08, 2005 4:11 am |
|
! = NOT  |
|
|
|
 |
CodyG
Life Cycles Becoming CPU Cycles

Joined: Jan 02, 2003
Posts: 714
Location: Vancouver Island
|
Posted:
Mon Aug 08, 2005 11:48 am |
|
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 |
|
|
 |
Raven

|
Posted:
Mon Aug 08, 2005 12:42 pm |
|
Code:where f.forum_id IN(34,35,36) AND t.forum_id=f.forum_id
|
|
|
|
|
 |
|