MyBB Community Forums

Full Version: Displaying News on your homepage
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
That means that something is still executing before the header stuff. Can you show me the code for your index page? PM me it if you don't want to post it here.
for get the pm i sent you MrDoom i got it i miss read your post Smile

okay but one more thing how it show the name of who posted in the news how can i make it it will have the name in there group color?
Haven't tested this but if you add the following under "$row2 = $db->fetch_array($query2);" it should work:
$query3 = $db->simple_select(TABLE_PREFIX."users", "displaygroup", "uid = '{$row2['uid']}'");
$gid = $db->fetch_field($query, "displaygroup");

$query4 = $db->simple_select(TABLE_PREFIX."usergroups", "namestyle", "gid = '{$gid}'");
$username = $db->fetch_field($query, "namestyle");

$username = str_replace("{username}", "$row2['username']", $username);

And then replace:
echo("<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['subject']}</a> - 
                Posted: {$date} {$time} by <a href=\"{$forumpath}member.php?action=profile&uid={$row2['uid']}\">{$row2['username']}</a><br />");
With:
echo("<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['subject']}</a> - 
                Posted: {$date} {$time} by <a href=\"{$forumpath}member.php?action=profile&uid={$row2['uid']}\">{$username}</a><br />");
nop gives error

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /mounted-storage/home43a/sub006/sc31956-OAMT/www/news.php on line 15
If line 15 is this:
$username = str_replace("{username}", "$row2['username']", $username);
Change it to:
$username = str_replace('{username}', "$row2['username']", $username);

If line 15 isn't that, try it anyway and if it still doesn't work, post your line 15 here.
okay error

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /mounted-storage/home43a/sub006/sc31956-OAMT/www/news.php on line 15

and page news.php

<?php
    $query = $db->simple_select(TABLE_PREFIX.'threads', '*', "fid='{$fid}' ORDER BY tid DESC LIMIT {$limit}");
    if($db->num_rows($query) > 0)
    {
        while($row = $db->fetch_array($query))
        {
            $query2 = $db->simple_select(TABLE_PREFIX.'posts', '*', "tid='{$row['tid']}' LIMIT 1");
            $row2 = $db->fetch_array($query2);
            $query3 = $db->simple_select(TABLE_PREFIX."users", "displaygroup", "uid = '{$row2['uid']}'");
$gid = $db->fetch_field($query, "displaygroup");

$query4 = $db->simple_select(TABLE_PREFIX."usergroups", "namestyle", "gid = '{$gid}'");
$username = $db->fetch_field($query, "namestyle");

$username = str_replace('{username}', "$row2['username']", $username); 
            $date = my_date($mybb->settings['dateformat'], $row2['dateline'], "", 1);
            $time = my_date($mybb->settings['timeformat'], $row2['dateline'], "", 1);

            $options = array(
                            'allow_html' => 'no',
                            'filter_badwords' => 'yes',
                            'allow_mycode' => 'yes',
                            'allow_smilies' => 'yes',
                            'nl2br' => 'yes',
                            'me_username' => 'yes'
                            );
            $message = $parser->parse_message($row2['message'], $options);
            
           echo("<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['subject']}</a> - 
                Posted: {$date} {$time} by <a href=\"{$forumpath}member.php?action=profile&uid={$row2['uid']}\">{$username}</a><br />"); 
            echo("{$message}<br /><br />");
            echo("Replies (<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['replies']}</a>)<br /><hr />");
        }
    }
    else
    {
        echo 'Nothing to display.';
    }

?>
Hi guys tried to implement this into my new site but I get header errors refering to the mybb functions file...

Warning: Cannot modify header information - headers already sent by
(output started at C:\Documents and Settings\Stargate SG-1\My Documents\Webdesigns\PHP\index.php:1)
in C:\Documents and Settings\Stargate SG-1\My Documents\Webdesigns\PHP\board\inc\functions.php on line 1133

Warning: Cannot modify header information - headers already sent by (output started at C:\Documents and Settings\Stargate SG-1\My Documents\Webdesigns\PHP\index.php:1)
in C:\Documents and Settings\Stargate SG-1\My Documents\Webdesigns\PHP\board\inc\functions.php on line 1133

Warning: Cannot modify header information - headers already sent by
(output started at C:\Documents and Settings\Stargate SG-1\My Documents\Webdesigns\PHP\index.php:1)
in C:\Documents and Settings\Stargate SG-1\My Documents\Webdesigns\PHP\board\inc\functions.php on line 1133

here is the php code I used inside the <body>

<?php

$fid = 2;
$limit = 5;
$forumpath = 'board/';
			
chdir($forumpath);
define("IN_MYBB", 1);
require('./global.php');
require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;
chdir('../');
				
$query = $db->simple_select(TABLE_PREFIX.'threads', '*', "fid='{$fid}' ORDER BY tid DESC LIMIT {$limit}");
	if($db->num_rows($query) > 0)
	{
		while($row = $db->fetch_array($query))
		{
			$query2 = $db->simple_select(TABLE_PREFIX.'posts', '*', "tid='{$row['tid']}' LIMIT 1");
			$row2 = $db->fetch_array($query2);
						
			$date = my_date($mybb->settings['dateformat'], $row2['dateline'], "", 1);
			$time = my_date($mybb->settings['timeformat'], $row2['dateline'], "", 1);
			
			$options = array('allow_html' => 'no', 
					       'filter_badwords' => 'yes', 
						'allow_mycode' => 'yes', 
						'allow_smilies' => 'yes', 
						'nl2br' => 'yes', 
						'me_username' => 'yes'
						);
			$message = $parser->parse_message($row2['message'], $options);
						
			echo("<h3><strong><a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['subject']}</a></strong> <small>- 
				Posted: {$date} {$time} by <a href=\"{$forumpath}member.php?action=profile&uid={$row2['uid']}\">{$row2['username']}</a></small></h3><br />");
			echo("<p>{$message}</p><br />");
			echo("<span style='color: #999999;'>Replies (<strong><a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['replies']}</a></strong>) - 
				Views <strong>{$row['views']}</strong></span>
				<br /><div style='border-bottom: 1px dashed #505050; margin: 2px 0 16px;'></div>");
			}
	}
	else
	{
		echo 'Nothing to display.';
	}
			
?>

Thanks.
@ Kames - You have the same error as crsoft did, please read here onwards.

@ crsoft - Can you try changing:
$username = str_replace('{username}', "$row2['username']", $username); 
To
$username = str_replace('{username}', $row2['username'], $username); 
Thanks very much, fixed Smile

Sorry I didn't read that far into the post.
Don't worry, I'm guilty of similar things myself. It's my fault for not making that clear in my original post, I'll go and edit it now.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33