Jump to content


Photo

My PHPBB news code needs fixed?


  • Please log in to reply
5 replies to this topic

#1 hlstriker

hlstriker
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 15 August 2006 - 10:44 PM

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.
<?
	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;
?>

If anyone could help me please do! Thanks!

#2 hlstriker

hlstriker
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 16 August 2006 - 12:15 AM

Just wondering if anyone could help me, I really need to get this fixed  :o

#3 fccid

fccid
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 16 August 2006 - 04:28 AM

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:

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
//

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:

//
// 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
//

original code by © smartor_xp@hotmail.com

#4 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 16 August 2006 - 05:02 AM

Hmm.. Shouldn't this be in 3rd party script ?

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#5 hlstriker

hlstriker
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 16 August 2006 - 03:24 PM

Hi fccid, thanks for posting, but i'm getting warnings on the page. Here is what I get...

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


Thanks.

#6 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 19 August 2006 - 10:13 AM

Check where you put your fetchposts.php

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users