MyBB Community Forums

Full Version: Help with thread display on external page
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All , wondered if some kind souls could help me please ,im trying to display threads from a certain forum on a external page this is the code i have so far

<?php
@mysql_connect("localhost", "root", "********") or die("Could not connect to MySQL");
@mysql_select_db("forum") or die("Could not connect to MySQL"); 


define("IN_MYBB", 1);

$tlimit = 5; // How many titles you want


$query = $db->query("SELECT * FROM ".TABLE_PREFIX."threads ORDER BY `tid` DESC LIMIT $tlimit");

    $list = '';
    while($fetch = $db->fetch_array($query))
    {
        $list .= " | <strong><a href=\"./showthread.php?tid={$fetch['tid']}\" target=\"_blank\">".htmlspecialchars_uni($fetch['subject'])."</a></strong>";

        $poster = "<a href=\"./member.php?action=profile&uid=".$fetch['uid']."\">{$fetch['username']}</a>";
        $list .= "Created by: {$poster}  ";
        
        
    }
echo $list;
?>

what do i need to add for it to display posts from one forum only ,also the current code i have added only seems to show thread title and poster and i would like it to display for example 500 characters of the thread ,i'm a bit of a noob with code so if you could kindly post my  above code with the extra lines needed in there i would be eternally gratefull

Thanks in advance Smile
Modify:
$query = $db->query("SELECT * FROM ".TABLE_PREFIX."threads ORDER BY `tid` DESC LIMIT $tlimit");
with:
$query = $db->query("SELECT * FROM ".TABLE_PREFIX."threads WHERE `fid`=XX ORDER BY `tid` DESC LIMIT $tlimit");
XX must be the id of the forum
Thank you added the ID ,but it doesnt show the thread content only the thread title and posted by ,what do i need to add to this to show the thread content ?
^ thread content doesn't exist in the threads table. it should be fetched from the posts table
$query = $db->query("SELECT * FROM ".TABLE_PREFIX."posts WHERE `fid`=XX AND `replyto`=0 ORDER BY `tid` DESC LIMIT $tlimit");

message field consists of thread content
That information is stored in the mybb_posts table.
$parser = new PostParser();
require_once MYBB_ROOT . "inc/class_parser.php");
$postquery = $db->query("SELECT p.*, u.* FROM " . TABLE_PREFIX . "posts p LEFT JOIN " . TABLE_PREFIX . "users u ON(p.uid=u.uid) WHERE p.visible=1 AND p.tid=" . $tid . " ORDER BY p.dateline ASC");
while($post => $db->fetch_array($postquery))
{
$post['profilelink'] = build_profile_link($post['uid'], format_name($post['username'], $post['usergroup'], $post['displaygroup']));
$post['message'] = $parser->parse_message($post['message']);
$post['time'] = my_date("relative", $post['dateline']);
}