Jump to content

Recommended Posts

Hey, I am trying to make a forum in PHPBB called News, display all the news in it's forum, on a custom news page on my main website. I have most of it written already, but some reson it doesn't display the poster name, and it puts all the post_text (the news itself) into the same table as the first news displayed.

Here is the code if anyone can tell me what to fix.
[code]<?
mysql_connect("host","user","pass");
mysql_select_db("db");

// Get the topics info and posts info
$querytopics = "SELECT topic_id, forum_id, topic_title, topic_poster, topic_replies FROM phpbb_topics";
$queryposts = "SELECT post_text FROM phpbb_posts_text";
$queryusers = "SELECT user_id, username FROM phpbb_users";

//Query the above...
$resulttopics = mysql_query($querytopics) or die('Error, query failed');
$resultposts = mysql_query($queryposts) or die('Error, query failed');
$resultusers = mysql_query($queryusers) or die('Error, query failed');


if((mysql_num_rows($resulttopics) == 0))
{
echo "News database is empty <br />";
} else {
while(list($topic_id, $forum_id, $topic_title, $topic_poster, $topic_replies) = mysql_fetch_array($resulttopics))
{
?>
<table border="1" cellspacing="0" cellpadding="3" align='center' width='100%' bgcolor='#000000'>
<tr>
<td colspan='2' align='left'><? echo $topic_title; ?></td>
</tr>
<tr>
<td colspan='2' align='left' valign='top'>
<?
while(list($post_text) = mysql_fetch_array($resultposts))
{
echo $post_text;
}
?>
</td>
</tr>
<tr>
<td align='left'><? echo $topic_replies; ?> replies</td>
<td align='right'>Posted by
<?
while(list($user_id, $username) = mysql_fetch_array($resultusers))
{
while(!$user_id == $topic_poster)
{
if($user_id == $topic_poster)
{
echo $username;
}
}
}
?>
</td>
</tr>
</table>
<br><br>
<?
}
}
mysql_close;
?>[/code]

If anyone could help me please do! Thanks!
Link to comment
https://forums.phpfreaks.com/topic/17690-my-phpbb-news-code-needs-fixed/
Share on other sites

first of all, why dont you just define the page as being in phpbb, to remove the hassle and the security problems you might encounter doing it that way..

usually this code on the very top:

[code]
define('IN_PHPBB', true);
$phpbb_root_path = 'forum/';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'fetchposts.'.$phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//
[/code]

that way, you dont have to manually do another query... here's the code to fetch the announcements, again you can define and customize it as you wish.. you can also output it in its own custom template, which declutters your code:

[code]//
// Fetch Posts from Announcements Forum
//
if(!isset($HTTP_GET_VARS['article']))
{
$template->assign_block_vars('welcome_text', array());

$fetchposts = phpbb_fetch_posts($CFG['news_forum'], $CFG['number_of_news'], $CFG['news_length']);

for ($i = 0; $i < count($fetchposts); $i++)
{
if( $fetchposts[$i]['striped'] == 1 )
{
$open_bracket = '[ ';
$close_bracket = ' ]';
$read_full = $lang['Read_Full'];
}
else
{
$open_bracket = '';
$close_bracket = '';
$read_full = '';
}

$template->assign_block_vars('fetchpost_row', array(
'TITLE' => $fetchposts[$i]['topic_title'],
'POSTER' => $fetchposts[$i]['username'],
'TIME' => $fetchposts[$i]['topic_time'],
'TEXT' => $fetchposts[$i]['post_text'],
'REPLIES' => $fetchposts[$i]['topic_replies'],
'U_VIEW_COMMENTS' => append_sid('viewtopic.' . $phpEx . '?t=' . $fetchposts[$i]['topic_id']),
'U_POST_COMMENT' => append_sid('posting.' . $phpEx . '?mode=reply&amp;t=' . $fetchposts[$i]['topic_id']),
'U_READ_FULL' => append_sid('portal.' . $phpEx . '?article=' . $i),
'L_READ_FULL' => $read_full,
'OPEN' => $open_bracket,
'CLOSE' => $close_bracket)
);
}
}
else
{
$fetchposts = phpbb_fetch_posts($CFG['news_forum'], $CFG['number_of_news'], 0);

$i = intval($HTTP_GET_VARS['article']);

$template->assign_block_vars('fetchpost_row', array(
'TITLE' => $fetchposts[$i]['topic_title'],
'POSTER' => $fetchposts[$i]['username'],
'TIME' => $fetchposts[$i]['topic_time'],
'TEXT' => $fetchposts[$i]['post_text'],
'REPLIES' => $fetchposts[$i]['topic_replies'],
'U_VIEW_COMMENTS' => append_sid('viewtopic.' . $phpEx . '?t=' . $fetchposts[$i]['topic_id']),
'U_POST_COMMENT' => append_sid('posting.' . $phpEx . '?mode=reply&amp;t=' . $fetchposts[$i]['topic_id'])
)
);
}
//
// END: Fetch Announcements
//[/code]

original code by (c) smartor_xp@hotmail.com
Hi fccid, thanks for posting, but i'm getting warnings on the page. Here is what I get...

[quote]Warning: include(forum/fetchposts.php) [function.include]: failed to open stream: No such file or directory in /(dirs)/news.php on line 8

Warning: include() [function.include]: Failed opening 'forum/fetchposts.php' for inclusion (include_path='.:/usr/local/php5/lib/php') in /(dirs)/news.php on line 8

Warning: Cannot modify header information - headers already sent by (output started at /(dirs)/news.php:8 ) in (dirs)/forum/includes/sessions.php on line 254

Warning: Cannot modify header information - headers already sent by (output started at /(dirs)/news.php:8 ) in (dirs)/forum/includes/sessions.php on line 255

Fatal error: Call to undefined function: phpbb_fetch_posts() in /(dirs)/news.php on line 26[/quote]

Thanks.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.