Last threads of a fluxBB forum on the home page
Having titles of last posts on a fluxBB forum (formerly punBB), on the home is very easy to obtain.
The fluxBB tables
In the tables, we want to recover the topic, the author and the publication date.
Contrary to what happens with phpBB, a single table provides all the necessary information and it is the topics table.
id is the
identifier of the first post of the discussion, it is used to build the URL.
subject is the title of the thread.
displayed is the date when it was opened.
poster is the name of the member of the forum who has open it.
Defining the request
The parameter FROM selects the topics table. The full name is built by adding the prefix provided by config.php.
The parameter SELECT defines the data to be returned and displayed, it is in order the identifier of the topic, the subject, the date of the post, the name of the member who made it.
Posts are ordered by date, in descending order, beginning with the most recent, and limited to a given number.
SELECT id, subject, displayed, poster FROM $top ORDER BY displayed DESC LIMIT $size";
The variable $size is a parameter of the script, it is the maximum number of titles to display.
Such a request is quick to perform and should not slow down the page display.
Getting access to settings of the base
The parameters of the host, the name of the database, user and password are recovered from the config.php file.
To do this, we simply define the path to the configuration file, the root of the forum, and we include this file in the script: variables it contains are then part of the script...
It is preferable to place the script at the root of the site for easier access to subdirectories (or into the forum's directory).
How to display the threads
We saw in the tutorial how to retrieve the data thanks to a basic function, mysql_fetch_assoc.
In our example, a style sheet is included that defines a framework and some properties for the data displayed. This is just an example and this must be adapted as required.
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";
Add or Remove span as needed, and replace the names of descriptors.
How to use the script
The script is included in the page that display the threads, and where you want to display them.
It must be configured according to the site:
$forumdir = "forum/"; $formatflag = false;
Change the name of the directory of the forum if needed, and activate the option of conversion to true if the page format is different from that of the forum (ISO).
It is also possible to choose the number of titles to be displayed with the last argument of the display function:
display($db_host, $db_name , $db_username, $db_password , 10);
Note that these variables come directly from config.php file included and are used directly.
Complete script and demonstration