Jump to content

Recommended Posts

Alright get ready for a headache cause I have one lol.

 

<table width="100%" border="0">
<? 
require('inc/config.php'); 
include('inc/bbcode.php');
$linkid = @mysql_connect("$db_host", "$db_uname", "$db_pass");
mysql_select_db("$db_name", $linkid);

//included are instructions on how to make multiple pages of news

// If current page number, use it 
// if not, set one! 

if(!isset($_GET['newspage'])){ 
    $newspage = 1; 
} else { 
    $newspage = $_GET['newspage']; 
} 

// Define the number of results per page 
$max_results = 4; 

// Figure out the limit for the query based 
// on the current page number. 
$from = (($newspage * $max_results) - $max_results); 

// Perform MySQL query on only the current page number's results 

$sql = mysql_query("SELECT topic_id, topic_title, topic_poster, topic_type, topic_replies FROM phpbb_topics where topic_type=3 order by topic_id desc LIMIT $from, $max_results"); 




while($row = mysql_fetch_array($sql)){ 

$sql2 = mysql_query("SELECT topic_id, post_id FROM phpbb_posts where topic_id=$row['topic_id']"); 
$row2 = mysql_query($sql2) or die("$sql2 does not make any sence;<br>" . mysql_error());
$contentrow2 = mysql_fetch_array($row2);

$sql3 = mysql_query("SELECT * FROM phpbb_posts_text where post_id=$contentrow2['post_id']"); 
$row3 = mysql_query($sql3) or die("$sql3 does not make any sence;<br>" . mysql_error());
$contentrow3 = mysql_fetch_array($row3);
    // Build your formatted results here. 
        echo '<tr><td><font size=3 color=#908F95><b>'.$row['topic_title'].'</b><br></td></tr></font>
<tr><td><font size=2 color=908F95>'.nl2br($contentrow3['post_text']).'</font></td></tr>
<tr><td><font size=2 color=#908F95><p align=right>''<br><br></p></font>';


// Figure out the total number of results in DB: 
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM phpbb_topics"),0); 

// Figure out the total number of pages. Always round up using ceil() 
$total_pages = ceil($total_results / $max_results); 

// Build Page Number Hyperlinks 
echo "<center><font size=2>Select a Page<br /></font>"; 

// Build Previous Link 
if($newspage > 1){ 
    $prev = ($newspage - 1); 
    echo "<font size=2><a href=\"".$_SERVER['PHP_SELF']."?newspage=$prev\"><<Previous</a> </font>"; 
} 

for($i = 1; $i <= $total_pages; $i++){ 
    if(($newspage) == $i){ 
        echo "$i "; 
        } else { 
            echo "<font size=2><a href=\"".$_SERVER['PHP_SELF']."?newspage=$i\">$i</a> </font>"; 
    } 
} 

// Build Next Link 
if($newspage < $total_pages){ 
    $next = ($newspage + 1); 
    echo "<font size=2><a href=\"".$_SERVER['PHP_SELF']."?newspage=$next\">Next>></a></font>"; 
} 
echo "</center>"; 
?>
</table>

 

There is my code.  What it is SUSPOSED to do is call up info from a phpbb database and get all the global announcements from the forum and post them in order but instead the page fatal errors.  The global announce field is this:  where topic_type=3

 

Here is how it works, or should.  phpbb_topics has the info that says ok topic created.  From there it links to phpbb_post via the mutual field topic_id.  From there phpbb_post links to phpbb_post_text via the field post_id.  And from that last field it gets the content of the post, but again the page crashes.  Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/115662-news/
Share on other sites

i had a quick review and updated 3-4 parts

<table width="100%" border="0">
<? 
require('inc/config.php'); 
include('inc/bbcode.php');
$linkid = @mysql_connect("$db_host", "$db_uname", "$db_pass");
mysql_select_db("$db_name", $linkid);

//included are instructions on how to make multiple pages of news

// If current page number, use it 
// if not, set one! 

if(!isset($_GET['newspage'])){ 
    $newspage = 1; 
} else { 
    $newspage = $_GET['newspage']; 
} 

// Define the number of results per page 
$max_results = 4; 

// Figure out the limit for the query based 
// on the current page number. 
$from = (($newspage * $max_results) - $max_results); 

// Perform MySQL query on only the current page number's results 

$sql = mysql_query("SELECT topic_id, topic_title, topic_poster, topic_type, topic_replies FROM phpbb_topics where topic_type=3 order by topic_id desc LIMIT $from, $max_results"); 




while($row = mysql_fetch_array($sql)){ //this wasn't closed (i closed it at the end)
$sql2 = mysql_query("SELECT topic_id, post_id FROM phpbb_posts where topic_id=".$row['topic_id']); //updated
$row2 = mysql_query($sql2) or die("$sql2 does not make any sence;<br>" . mysql_error());
$contentrow2 = mysql_fetch_array($row2);

$sql3 = mysql_query("SELECT * FROM phpbb_posts_text where post_id=".$contentrow2['post_id']); //updated
$row3 = mysql_query($sql3) or die("$sql3 does not make any sence;<br>" . mysql_error());
$contentrow3 = mysql_fetch_array($row3);
    // Build your formatted results here. 
        echo '<tr><td><font size=3 color=#908F95><b>'.$row['topic_title'].'</b><br></td></tr></font>
<tr><td><font size=2 color=908F95>'.nl2br($contentrow3['post_text']).'</font></td></tr>
<tr><td><font size=2 color=#908F95><p align=right><br><br></p></font>';
        

// Figure out the total number of results in DB: 
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM phpbb_topics"),0); 

// Figure out the total number of pages. Always round up using ceil() 
$total_pages = ceil($total_results / $max_results); 

// Build Page Number Hyperlinks 
echo "<center><font size=2>Select a Page<br /></font>"; 

// Build Previous Link 
if($newspage > 1){ 
    $prev = ($newspage - 1); 
    echo "<font size=2><a href=\"".$_SERVER['PHP_SELF']."?newspage=$prev\"><<Previous</a> </font>"; 
} 

for($i = 1; $i <= $total_pages; $i++){ 
    if(($newspage) == $i){ 
        echo "$i "; 
        } else { 
            echo "<font size=2><a href=\"".$_SERVER['PHP_SELF']."?newspage=$i\">$i</a> </font>"; 
    } 
} 

// Build Next Link 
if($newspage < $total_pages){ 
    $next = ($newspage + 1); 
    echo "<font size=2><a href=\"".$_SERVER['PHP_SELF']."?newspage=$next\">Next>></a></font>"; 
}
echo "</center>"; 

}
?>
</table>

Link to comment
https://forums.phpfreaks.com/topic/115662-news/#findComment-594584
Share on other sites

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.