MyBB Community Forums

Full Version: Show last 5 Thread on web page !
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, can anybody tell me how to display last 5 thread on my web page, but I need to subject be short max 18 characters like:

- What is your opini ...
- How look your boyf ...

ETC
do you know any PHP?

basically all you need to do is do an SQL select from mybb threads, order by post date descending and limit 5.

then you can just use substr to shorten the lengths of the titles.

<?php

$mysqlserver = "localhost";
$mysqluser = "username";
$mysqlpassword = "password";
$mysqldb = "database";

$tableprefix = "mybb_";
$pathtoforums = "http://mydomain.com/forums/";


//Connect
mysql_connect($mysqlserver,$mysqluser,$mysqlpassword);
mysql_select_db($mysqldb);


$threadquery = mysql_query("SELECT * FROM `".$tableprefix."threads` ORDER BY `lastpost` DESC LIMIT 5");

while($thread = mysql_fetch_array($threadquery)){
   $title = substr($thread['subject'],0,"18");
   $title = $title."...";

   echo "<a href="".$pathtoforums."showthread.php?tid=\"".$thread['tid']."\">".$title."</a>\r\n";
}
?>

fill in the variables and its the most basic form of what you want. edit as you please.

i might have made a few errors while coding and is not tested.