Jump to content
xisto Community
jlhaslip

[aef] Most Recent Topics Listing Mod on your Web-site pages

Recommended Posts

Assuming that you have an AEF Forum software installed on your Hosting Account, and that you need [or want] to display a list of the most Recent Topics to be display, say, on your Index page, then read this Tutorial.

To begin, Define the variables that you need to connect to the Database and also define the URL to the Forum in the prescribed format as follows:

<?php //start the script//define db information hereDEFINE ('DB_USER', '  '); // required infoDEFINE ('DB_PASSWORD', '  '); // required infoDEFINE ('DB_HOST', 'localhost'); // required info. localhost works frequentlyDEFINE ('DB_NAME', '  '); // required infoDEFINE ('FORUM_URL', 'http://[sub-domain.]domain.com/[aef_folder]/index.php?tid='); // required info// the optional parts are inside square brackets ie: sub-domain and folder// include the parts you require in your URL
Connect to the Database and select the Database for the Query, and run the Query
// Connect to the db.// Make the connection.$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );// Select the database.@mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() );// Make the query. Select the last 5 topics. adjust the LIMIT quantity to suit your needs$query = "SELECT `tid`,`topic`,`t_description` FROM `aef_topics` ORDER BY `tid` DESC LIMIT 5 ";		$result = @mysql_query ($query); // Run the query.
The following variables are actually used for in-line CSS so that the script can be styled independently of the site CSS file. Of course, you could also remove them and use the Div ID to style the output via the CSS file, but that is another Tutorial. :)
$dl_div_bg = '#bbbbbb'; // Set the div background color$dl_bg = '#cccccc'; // Set the dl background color$dt_bg = '#dddddd'; // Set the dt background color$dd_bg = '#eeeeee'; // Set the dd background color
Now that you have the database open and the Query results in an array, the script needs to start its output. I have chosen to include the results inside a Div with an ID, and its own header, so that this div can be specified in your CSS file. If you do that, remove the styling variable values from the script .
// start div and dl hereecho '<div id="forum_topics"  style=" width: 220px; padding-left:15px; padding-bottom: 10px; background-color: ' . $dl_div_bg . '" ><br /><h3 style=" margin-top: 5px; width: 200px; background-color:' . $dd_bg . '" >Latest Forum Topics</h3> <dl id="defn_list" style="background-color:' . $dd_bg . '; width: 200px; ">' . "\n";
Use a while statement to display the results as a Definition List, with Definition Terms and Definition Data. Again, the style info is in-line, but could be external to the script if you choose to do so.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { // loop through the results	echo "\t" . '<dt style=" background-color: ' . $dt_bg . '"><a href="' . FORUM_URL, $row['tid'] . '">' . $row['topic'] . '</a></dt>' . "\n";	echo "\t\t" . '<dd style=" background-color: ' . $dd_bg . '">' . $row['t_description'] . '</dd>';}echo '</dl></div'; // end the dl and div here// tidy up the db stuffmysql_free_result ($result); // Free up the resources.	mysql_close(); // Close the database connection.?>
The last segment also frees the results and closes the connection to the Database as an example of good programming style.

To add this script to your site, simply paste the code (in the listed order) into your page. (or use the attached file)
Of course, you need to name the file with a php extension (or adjust the application-handler for html to get it parsed as php), but that is another Tutorial. :)

p.s.: notice also, that the script uses the 'control characters' to add tabs and new-lines to the html output. (do a view source to see them in action). that makes reading the source code a lot easier to understand.

Hope you enjoyed the Tutorial. Hope you install an AEF Forum and enjoy both the Forum and this script.

last_tut.php

Share this post


Link to post
Share on other sites

Nice Tutorial Jim! :) Will come in handy. :)Say, are we allowed to do Tutorials for cPanel etc and for the hosting, network and community? Just like "How to edit your profiles personal picture" or "How to edit your Avatar" etc?-Sky

Share this post


Link to post
Share on other sites

Say, are we allowed to do Tutorials for cPanel etc and for the hosting, network and community? Just like "How to edit your profiles personal picture" or "How to edit your Avatar" etc?

I think the Tutorials for these are all completed. Check the Tutorial section under "Contribute" sub-forum. Or use the Search feature.
And thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.