1

Topic: News comment page - query problem

Right, what I'm trying to do is fetch the first post in the topic, the actual post of the topic creator - this is for news, a full news view so to say (when you click the news you come to this page - Page with the news and the comments after).

Ive already managed to get all the comments, but having trouble getting a query only for the first post.

This is what it looks for the code for fetching the first topic post looks like at the moment:

    // Fetch some info about the news
$result = $db->query('SELECT t.id, t.subject, t.num_replies, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.forum_id, f.id AS forum_id, f.forum_name, f.moderators, fp.post_replies, p.poster, p.poster_id, p.message, p.hide_smilies, p.posted 
                FROM '.$db->prefix.'topics AS t 
                INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id 
                INNER JOIN ' . $db->prefix . 'posts AS p ON topic_id='.$id.'
                INNER JOIN ' . $db->prefix . 'users AS u ON u.id=p.poster_id
                LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') 
                WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.id='.$id.' AND t.moved_to IS NULL') or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
if ($db->num_rows($result))
        {
            $cur_topic = $db->fetch_assoc($result);
            $cur_post = $db->fetch_assoc($result);
            while($cur_post)
            {
                $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);

                echo '
                <h1>'.$cur_topic['subject'].'</h1>
                <p>'.$cur_post['message'].'<br /></p>
                <h3>'.$news_actions.'</h3>
                ';

                $cur_post = $db->fetch_assoc($result);
                if( $cur_post ) echo '';
            }    
    }

and Its not working properly (just giving me all the posts after the first post at the moment).

Could anyone help me with this? smile

Re: News comment page - query problem

this is what i use to pull the news from any topic that i want you will notice at the top. the newid set that to the forum id.1 2 3 4 etc.
then u will notice a newsdisplay that how many you want to pull..

ok here the link to my site http://bunpai.com a internet one stop shop for news.
you will have to modify the images and buttons not unless you want me to send them to you.

Q


<?php
$newsid = '8'; // Forum id to fetch the news from ( only supports 1 forum id )
$newsdisplay = '1'; // Number of news to display.

?>

<?php
require_once PUN_ROOT.'include/parser.php';

?>
<div class="boxtop"></div>
            <div class="box">



<?
$result = $db->query('SELECT t.id, t.subject, t.num_replies, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.forum_id, p.poster, p.poster_id, p.message, p.hide_smilies, p.posted, g.g_title, f.forum_name FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'posts AS p ON p.topic_id=t.id AND p.posted=t.posted INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id WHERE t.forum_id='.$newsid.' AND t.moved_to IS NULL AND f.redirect_url IS NULL ORDER BY t.posted DESC LIMIT '.$newsdisplay) or error('Unable to fetch announcements', __FILE__, __LINE__, $db->error());

if ($db->num_rows($result))
                    {
                            while($cur_post = $db->fetch_assoc($result))
                            {
                                    $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
?>

<?
echo "\t\t\t\t\t\t\t".'<p><img src="images/image.gif" alt="Image" title="Image" class="image" /><b> '.pun_htmlspecialchars($cur_post['subject']).'</b><br />'."\n";
?>


<?php echo $cur_post['message']."\n" ?><br /></p>


<?
echo "\t\t\t\t\t\t\t".'<div class="buttons"><p><a href="viewtopic.php?id='.$cur_post['id'].'" class="bluebtn">'.'Read'.'</a>'."\n";
?>


</div>
            </div>





<?
}
 }
else
{

 }    
?>
My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!