Thread Rating:
  • 2 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Displaying News on Homepage
#11
Still not working, I'll just use the portal it came with , thanks for the help.
Reply
#12
Right. Finally got it working via MSN. Here is the final code
PHP Code:
<?php
$mysqlhost 
"localhost";
$mysqlusername "";
$mysqlpassword "";
$mysqldbselect "";
$prefix "mybb_";
$fid "2";

mysql_select_db($mysqldbselectmysql_connect($mysqlhost,$mysqlusername,$mysqlpassword));

$query mysql_query("SELECT t.tid,t.subject,t.uid,t.username,t.replies,p.message FROM ".$prefix."threads t LEFT JOIN ".$prefix."posts p ON (t.tid = p.tid) WHERE t.fid='".$fid."' AND t.visible='1' AND t.closed NOT LIKE 'moved|%'") or die(mysql_error());
while(
$news mysql_fetch_array($query))
{
echo 
"<a href=\"./forum/showthread.php?tid=".$news['tid']."\">".$news['subject']."</a> | Posted by: <a href=\"./forum/member.php?action=profile&amp;uid=".$news['uid']."\">".$news['username']."</a> | Replies: <a href=\"./forum/showthread.php?tid=".$news['tid']."\">".$news['replies']."</a><hr />".$news['message']."<br /><br />";
}
?>
Reply
#13
Works beautifuly. Hmm wish there was a way to parse the bbcodes tho.
NetAdmin @ PharosIRC
irc.pharosirc.net
#Help,#lobby,#linux
MrStatic
Reply
#14
Works, many thanks! Smile

By the way, it also displays comments as an actual news post, I am going to see if I can fix that.
Suprisingly simple, just add...

Code:
WHERE p.replyto='0'

in the query. Then you only get the first post of each thread.
Reply
#15
great idea
Reply
#16
What about adding an avatar and such?
Reply
#17
Right. Because of the requests and a few bugs found, here is the new code. It now has a forum path value, which means it can now use MyBB's config file and correct all link/image paths itself instead of having to edit multiple details yourself. You can also now limit how many to show (default is 10), it should also order the posts to show the latest ones (not random ones) and only show the starting posts, not replies. It also displays the poster's avatar and the time the thread was made in a new outputting style.
PHP Code:
<?php
$forumpath 
"./MyBBForum/"// Path to your forums root directory (with trailing slash)
$fid "2"// The forum ID to pull the annoucements from
$limit "10"// The amount of annoucements to show

require $forumpath."inc/config.php";
mysql_select_db($config['database'], mysql_connect($config['hostname'], $config['username'], $config['password']));

$query mysql_query("SELECT t.tid,t.subject,t.uid,t.username,t.dateline,t.replies,p.message,u.avatar FROM ".$config['table_prefix']."threads t LEFT JOIN ".$config['table_prefix']."posts p ON (t.tid = p.tid) LEFT JOIN ".$config['table_prefix']."users u ON (t.uid = u.uid) WHERE t.fid='".$fid."' AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND p.replyto='0' ORDER BY t.tid DESC LIMIT 0, ".$limit."") or die(mysql_error());
while(
$news mysql_fetch_array($query))
{
    
$date gmdate("d-m-Y"$news['dateline']);
    
$time gmdate("h:i A"$news['dateline']);
    if(
$news['replies'] == "1")
    {
        
$replytext "reply";
    }
    else
    {
        
$replytext "replies";
    }
    if(
$news['avatar'] != "")
    {
        if(
substr($news['avatar'], 07) != "http://")
        {
            
$url $forumpath;
        }
        
$avatarbit "<td valign=\"top\" style=\"border: solid 1px #000000;\" rowspan=\"2\" width=\"150\" align=\"center\"><img src=\"".$url.$news['avatar']."\" alt=\"".$url.$news['avatar']."\" /></td>";
    }
    else
    {
        
$avatarbit "";
    }
    echo 
"<table cellpadding=\"7\" align=\"center\" style=\"border: solid 0px #000000;\" width=\"100%\">\n";
    echo 
"<tr>".$avatarbit."<td style=\"border: solid 1px #000000;\"\"><a href=\"".$forumpath."showthread.php?tid=".$news['tid']."\">".$news['subject']."</a> ( ".$news['replies']." ".$replytext." ) <br />Posted by <a href=\"".$forumpath."member.php?action=profile&amp;uid=".$news['uid']."\">".$news['username']."</a> on ".$date." at ".$time."</td></tr>\n";
    echo 
"<tr><td style=\"border: solid 1px #000000;\"\">".$news['message']."</td></tr>\n";
    echo 
"</table><br />\n\n";
}
?>
I'm also in the middle of implementing BBcodes.
Reply
#18
k776 Wrote:Right. Because of the requests and a few bugs found, here is the new code. It now has a forum path value, which means it can now use MyBB's config file and correct all link/image paths itself instead of having to edit multiple details yourself. You can also now limit how many to show (default is 10), it should also order the posts to show the latest ones (not random ones) and only show the starting posts, not replies. It also displays the poster's avatar and the time the thread was made in a new outputting style.
PHP Code:
<?php
$forumpath 
"./MyBBForum/"// Path to your forums root directory (with trailing slash)
$fid "2"// The forum ID to pull the annoucements from
$limit "10"// The amount of annoucements to show

require $forumpath."inc/config.php";
mysql_select_db($config['database'], mysql_connect($config['hostname'], $config['username'], $config['password']));

$query mysql_query("SELECT t.tid,t.subject,t.uid,t.username,t.dateline,t.replies,p.message,u.avatar FROM ".$config['table_prefix']."threads t LEFT JOIN ".$config['table_prefix']."posts p ON (t.tid = p.tid) LEFT JOIN ".$config['table_prefix']."users u ON (t.uid = u.uid) WHERE t.fid='".$fid."' AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND p.replyto='0' ORDER BY t.tid DESC LIMIT 0, ".$limit."") or die(mysql_error());
while(
$news mysql_fetch_array($query))
{
    
$date gmdate("d-m-Y"$news['dateline']);
    
$time gmdate("h:i A"$news['dateline']);
    if(
$news['replies'] == "1")
    {
        
$replytext "reply";
    }
    else
    {
        
$replytext "replies";
    }
    if(
$news['avatar'] != "")
    {
        if(
substr($news['avatar'], 07) != "http://")
        {
            
$url $forumpath;
        }
        
$avatarbit "<td valign=\"top\" style=\"border: solid 1px #000000;\" rowspan=\"2\" width=\"150\" align=\"center\"><img src=\"".$url.$news['avatar']."\" alt=\"".$url.$news['avatar']."\" /></td>";
    }
    else
    {
        
$avatarbit "";
    }
    echo 
"<table cellpadding=\"7\" align=\"center\" style=\"border: solid 0px #000000;\" width=\"100%\">\n";
    echo 
"<tr>".$avatarbit."<td style=\"border: solid 1px #000000;\"\"><a href=\"".$forumpath."showthread.php?tid=".$news['tid']."\">".$news['subject']."</a> ( ".$news['replies']." ".$replytext." ) <br />Posted by <a href=\"".$forumpath."member.php?action=profile&amp;uid=".$news['uid']."\">".$news['username']."</a> on ".$date." at ".$time."</td></tr>\n";
    echo 
"<tr><td style=\"border: solid 1px #000000;\"\">".$news['message']."</td></tr>\n";
    echo 
"</table><br />\n\n";
}
?>
I'm also in the middle of implementing BBcodes.

That is excellent. Thank's for your time. Sorry to annoy you via PM. Wink
Ok, we've modified your code to produce this:

http://dc.peerweb.org/ Big Grin

BBcode works. Haven't tried with the emoticons though.
Reply
#19
Mind post or Pmin me that code...thats would rock. Big Grin
Reply
#20
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)