Show recent phpBB discussion headers

Script for displaying the titles of recent posts on the phpBB forum (version 2) on the site page, usually on the home page.

phpBB Tables

To get information for display, you need to look at three tables: title, author and date.

Ticket desk

post_id post_time
   

In this table, we will read the ticket ID that is used for the relationship between the tables.
We also take the release date of the ticket that may be shown and will use it to sort the latest tickets.

Table of topics

post_id topic_id topic_first_post_id topic_poster
       

It provides the ID of the first discussion ticket, it will be used to build the URL.
The post author ID will be used to access data from the user table.

Enumerator Table

user_id username
   

It contains the names of the forum participants. User_id corresponds to the topic_poster in the table of topics.

Query definition

The FROM option selects the tables: Messages, topics, users.
The full name is built by adding a prefix.

The SELECT parameter determines the data that will be returned and displayed, it is in order the identifier of the topic, the subject of the ticket, the date of the ticket, the name of the participant who sent it.

Tickets are selected by the WHERE clause, supplemented by I. Select tickets from those who start the discussion and users who match the number found in the topic table.

$sql = "SELECT TOP.topic_id, TOP.topic_title, TOP.topic_time, USER.username 
        FROM $posts REF, $users USER, $top TOP
        WHERE REF.post_id = TOP.topic_first_post_id     
        AND TOP.topic_poster = USER.user_id
        ORDER BY REF.post_time DESC LIMIT $size";

The variable $ size is a script parameter, which is the maximum number of headers to display.

Retrieving database access settings

To make the program more general, the database name, user and password parameters are extracted from the set.php file.

To do this, it is enough to set the path to the configuration file, to the root of the forum, and include this file in our script: the variables contained in it will then belong to the script...

Show data

Previously, you could see how to extract data obtained in the database using the mysql_fetch_assoc function.

The string displaying the data is just an example. It displays the name of the ticket, the name of the participant, the date.

echo "<a href='$url'>$title</a> by 
<span class='cssuser'>$username</span>  
<span class='cssdate'>$date</span>\n";

It can be adapted as needed.

Use script

The script is included in the page where the headers are displayed and where you want them to appear.

It needs to be configured depending on the site:

$site = "http://www.scriptol.com/";   
$forumdir = "forum/";    
$formatflag = false; 

If necessary, replace the URL with the site URL, the forum directory, and set the conversion option to true if the page format differs from the forum format.

You can also select the number of headers to display with the last option of the display function:

display($dbhost, $dbname , $dbuser, $dbpasswd , 10);  

Note that variables that generate other parameters come from the included set.php file.

Full script

The forum used to test the script is located on another site, it is impossible to directly show the demo (and this site uses punBB, not phpBB).

See also