Page 1 of 1

Recent Topics on the Forum...

Posted: Thu May 04, 2006 1:25 pm
by HaxxoR
Hello

I have a PHP Nuke website. I made the block who shows 10 Recent Topics on the forum (the topics who have been commented and opened recently). So I discovered that this block isnt going too well. It shows wrong topics! So I need help. Can someone post a PHP Code that I can just flip in the custom block and its shows me 10 recent topics?

Please

Thanx everyone who helped me in advance

Posted: Thu May 04, 2006 1:28 pm
by ozzy
Hey HaxxoR :? ,

you could try posting in your 'block' and we could look through it for you, and hopefully point out where you are going wrong.

Posted: Thu May 04, 2006 1:36 pm
by HaxxoR

Code: Select all

if (stristr($_SERVER['SCRIPT_NAME'], "block-Last_5_Forum_Posts.php")) {
    Header("Location: ../index.php");
    die();
}

global $prefix, $db, $sitename, $user, $user_prefix, $cookie, $gotuserid, $gotusegroup;

$result = $db->sql_query("SELECT forum_id, topic_id, topic_title FROM ".$prefix."_bbtopics ORDER BY topic_time DESC LIMIT 10");

cookiedecode($user);
$uname = $cookie[1];

if (isset($uname)) {
	$finduserid = $db->sql_fetchrow($db->sql_query("SELECT user_id FROM ".$prefix."_users WHERE username='$uname'"));
	$gotuserid = intval($finduserid['user_id']);
	$findgroupid = $db->sql_fetchrow($db->sql_query("SELECT group_id FROM ".$prefix."_bbuser_group WHERE user_id='$gotuserid'"));
	$gotgroupid = intval($findgroupid['group_id']);
}

while ($row = $db->sql_fetchrow($result)) {
    $forum_id = intval($row['forum_id']);
    $topic_id = intval($row['topic_id']);
    $topic_title = $row['topic_title'];
    $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 (isset($uname)) {
	    if (($auth_view >= 2) OR ($auth_read >= 2)) {
			$authresult = $db->sql_query("SELECT group_id, forum_id FROM ".$prefix."_bbauth_access WHERE group_id='$gotgroupid'");
			while ($authrow = $db->sql_fetchrow($authresult)) {
				$authforum_id = intval($authrow['forum_id']);
				if ($forum_id == $authforum_id) {
			        $content .= "<img src=\"images/arrow.gif\" border=\"0\" alt=\"\" title=\"\" width=\"9\" height=\"9\">&nbsp;<a href=\"modules.php?name=Forums&file=viewtopic&t=$topic_id\">$topic_title</a><br>";
		        }
			}
	    }
	}
    if (($auth_view < 2) OR ($auth_read < 2)) {
        $content .= "<img src=\"images/arrow.gif\" border=\"0\" alt=\"\" title=\"\" width=\"9\" height=\"9\">&nbsp;<a href=\"modules.php?name=Forums&file=viewtopic&t=$topic_id\">$topic_title</a><br>";
    }
}

?>

Posted: Sat May 06, 2006 4:12 pm
by Jim_Bo
Hi,

I made this ages ago to pull the latest posts from v.bulletin .. Just modify it to suit phpnuke maybe ...

Code: Select all

<?php 

require 'db.php';

$heaading = "#666666";				// Change hex to suit your color needs for heading
$color1 = "#666666"; 				// Change hex to suit your color needs for alternating rows 
$color2 = "#797170"; 				// Change hex to suit your color needs for alternating rows

$vip = "10";						// Exclude the VIP forum from all members
$threads = "5";						// Change to display how many recent threads you want to display

// Dont alter below this line!

$connection = mysql_pconnect("$dbhost","$dbuser","$dbpasswd") 
	or die ("Couldn't connect to server.");
	
$db = mysql_select_db("$database", $connection)
	or die("Couldn't select database.");

echo '<table width="98%" border="0" align="center" cellpadding="5" cellspacing="1">
  <tr> 
    <td width="35%" bgcolor="'.$heaading.'"><div align="center"><b>Posted By</b></div></td>
    <td width="10%" bgcolor="'.$heaading.'"><div align="center"><b>Topic</b></div></td>
    <td width="10%" bgcolor="'.$heaading.'"><div align="center"><b>Views</b></div></td>
    <td width="5%" bgcolor="'.$heaading.'"><div align="center"><b>Replys</b></div></td>
  </tr>';

$sql = "select t.postusername as postername
     , t.threadid 
	 , t.title
     , t.views
     , t.replycount
	 , t.forumid
	 , p1.username as lastposter
	 , p1.postid
	 , p1.pagetext 
     , p1.dateline
  from vb3_thread as t
inner
  join vb3_post as p1
    on t.threadid = p1.threadid
inner
  join vb3_post as p2
    on t.threadid = p2.threadid
where t.forumid <> $vip 
group
    by t.postusername  
     , t.title
     , t.views
     , t.replycount
     , p1.username  
     , p1.pagetext      
     , p1.dateline
having p1.dateline
     = max(p2.dateline)
order
    by t.dateline desc
limit $threads";

$result = mysql_query($sql) or die ("Query failed"); 
while ($row = mysql_fetch_array($result)) {
$threadid  = $row['threadid'];
$postid = $row['postid'];
$title = $row['title']; 
$replycount = $row['replycount']; 
$postername = $row['postername'];
$lastposter = $row['lastposter'];
$views = $row['views'];
$pagetext = nl2br($row['pagetext']);

$row_color = ($row_count % 2) ? $color1 : $color2; 

echo '<tr valign="top">
    <td bgcolor="'.$row_color.'"><div align="left">'.$postername.'<br><br><b>Last Poster</b><br><br>'.$lastposter.'<br></div></td>
    <td width="74%" bgcolor="'.$row_color.'"><div align="left">'.$title.'<br><br><b>Posted -{</b> <a class="two" href="/forum/showthread.php?p=$postid#" target="_blank">Read full thread</a> <b>}-</b><br><br>'.$pagetext.'</div></td>
    <td width="10%" bgcolor="'.$row_color.'"><div align="center">'.$views.'</div></td>
    <td bgcolor="'.$row_color.'"><div align="center">'.$replycount.'</div></td>
  </tr>';

$row_count++; 

} 
 
echo '</table><br>';

?>

hth