Getting the 5 most recent posts in a forum

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Post Reply
ironmagma
Registered User
Posts: 5
Joined: Wed Mar 08, 2006 10:45 pm
Contact:

Getting the 5 most recent posts in a forum

Post by ironmagma »

Hi. This may seem like a silly question, but I am *trying* to write a PHP script to retrieve the Poster Name, Subject, Body, and number of comments from the last 5 posts on a forum (any forum named "News", that is), and I get the feeling that I am going about it all wrong. Here's what I have now:

Code: Select all

<?

 $dbh=mysql_connect ("localhost", "(username here)", "(pw here)") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("(db here)");

$query = 'SELECT * FROM phpbb_forums';

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML

$td=0;

$tocount=array();

$lastnum="";

while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {

$ln=0;

   foreach ($line as $col_value) {
if($ln == 0)
{
$lastnum=$col_value;
}
if($ln == 2 && strtolower($col_value) == "news")
{
$tocount[count($tocount)] = $col_value;
}
$ln++;
   }


$td++;

}

$again = 'SELECT * FROM phpbb_topics';

$rs2 = mysql_query($again) or die('Query failed: ' . mysql_error());



// then do a processing of the topics, getting the info from there, and so on.



// Closing connection
mysql_close($dbh);

?>
Any ideas? Thanks!

chrisb123
Registered User
Posts: 409
Joined: Fri Jan 20, 2006 4:05 am
Location: Bury, UK

Post by chrisb123 »

this mod already exists

User avatar
drathbun
Former Team Member
Posts: 12204
Joined: Thu Jun 06, 2002 3:51 pm
Location: TOPICS_TABLE
Contact:

Post by drathbun »

chrisb123 wrote: this mod already exists

So? :-P Post a link, then, or do something a bit more helpful! ;-)

To the original poster, we have a forum for folks that are writing code to modify their forums, so I'll move your topic there.
I blog about phpBB: phpBBDoctor blog
Still using phpbb2? So am I! Click below for details
Image

ironmagma
Registered User
Posts: 5
Joined: Wed Mar 08, 2006 10:45 pm
Contact:

Post by ironmagma »

I'm still not quite sure what a "MOD" is, but I assume that it is an extension for phpBB. I need to do this in an external script, so I'm not sure if a MOD would help. Does anyone have a link to the MOD?

EJeanmaire
Registered User
Posts: 4
Joined: Thu Mar 09, 2006 9:08 pm

Post by EJeanmaire »

you could save alot of sweat by just modifying your Query:
$sql = 'SELECT * FROM `phpbb_posts` ORDER by post_time DESC LIMIT 0 , 5';

This can be tweaked up even a bit more but this will give you what you are looking for. HTH

Post Reply

Return to “[2.0.x] MOD Writers Discussion”