View recent discussion headers on the flowBB forum
For example, getting the headers of the latest flowBB/punBB forum messages on the site page is very easy.
FlowBB Tables
In the tables I want to return the topic of discussion, author and publication date.
Unlike what happens with phpBB, only one table provides all the necessary information, this is the topics table.
same
|
subjective
|
published by
|
poster
|
id is the ID of the first post in the discussion, it is used to build the URL.
subject - the name of the discussion.
posted - the date when it was opened.
poster is the name of the forum member who opened it.
Query definition
The FROM option selects the topic table. The full name is built by adding the prefix provided by set.php.
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 classified by dates, respectively, in descending order, starting with the latter and limited to a given number.
SELECT id, subject, posted, poster
FROM $top
ORDER BY posted DESC LIMIT $size";
The variable $ size is a script parameter, which is the maximum number of headers to display.
This request is fast and should not slow down the page display.
Retrieving database access settings
The host parameters, database name, user, and password 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...
It is better to place the script at the root of the site for easy access to subdirectories.
How discussions are displayed
In the tutorial, you saw how to extract the received data from the database using the mysql_fetch_assoc function.
Our example includes a style sheet that defines the borders and some properties of the displayed data. This is just one example and needs to be adapted as needed.
For the stylesheet included in the demo page, the script uses the following line:
echo "<a href='$url'>$title</a> by
<span class='cssuser'>$username</span>
<span class='cssdate'>$date</span>\n";
If necessary, add or remove pages and replace descriptor names.
How to use a 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:
$forumdir = "faq/";
$formatflag = false;
If necessary, change the name of the forum directory and enable the conversion option to true if the page format is different from the forum (ISO) format.
You can also select the number of headers to display with the last option of the display function:
display($db_host, $db_name , $db_username, $db_password , 10);
Note that these variables in the settings are taken directly from the included set.php file and are used as such.
Full script and demo
- See source code.
- Load script with demo page.
See also