MyBB Community Forums

Full Version: Displaying News on your homepage
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
(2009-06-04, 02:55 PM)bombo Wrote: [ -> ]change:

$query = $db->simple_select(TABLE_PREFIX.'threads', '*', "fid='{$fid}' ORDER BY tid DESC LIMIT {$limit}");

into:

$query = $db->simple_select(TABLE_PREFIX.'threads', '*', "fid='{$fid}' AND tid='your treadid' ORDER BY tid DESC LIMIT {$limit}");
Thanks Smile

But I don't think that does exactly what I'm trying to do. What I'm looking for is a change so I can specify a specific post id so only that post (may it be the first, the 8th or the 312th) will be shown in the output.

I tried the above change and tried to either put the thread id in the tid='yourthreadid' or the post id. Both result in a message "Nothing to display".
When I try this I get a MySQL Error

Here is the error
MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.
SQL Error:
1146 - Table 'animefro_xelium.mybb_mybb_threads' doesn't exist
Query:
SELECT * FROM mybb_mybb_threads WHERE fid='1' ORDER BY tid DESC LIMIT 4

Please contact the MyBB Group for support.

my news.inc.php code
<?php
    
    $query = $db->simple_select(TABLE_PREFIX.'threads', '*', "fid='{$fid}' ORDER BY tid DESC LIMIT {$limit}");
    if($db->num_rows($query) > 0)
    {
        while($row = $db->fetch_array($query))
        {
            $query2 = $db->simple_select(TABLE_PREFIX.'posts', '*', "pid='{$row['firstpost']}'");
            $row2 = $db->fetch_array($query2);
            
            $date = my_date($mybb->settings['dateformat'], $row2['dateline'], "", 1);
            $time = my_date($mybb->settings['timeformat'], $row2['dateline'], "", 1);

            $options = array(
                            'allow_html' => 'no', 
                            'filter_badwords' => 'yes', 
                            'allow_mycode' => 'yes', 
                            'allow_smilies' => 'yes', 
                            'nl2br' => 'yes', 
                            'me_username' => 'yes'
                            );
            $message = $parser->parse_message($row2['message'], $options);
            
            echo("<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['subject']}</a> - 
                Posted: {$date} {$time} by <a href=\"{$forumpath}member.php?action=profile&uid={$row2['uid']}\">{$row2['username']}</a><br />");
            echo("{$message}<br /><br />");
            echo("Replies (<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['replies']}</a>)<br /><hr />");
        }
    }
    else
    {
        echo 'Nothing to display.';
    }

?>
Use this Wink

<?php
    
    $query = $db->simple_select('threads', '*', "fid='{$fid}' ORDER BY tid DESC LIMIT {$limit}");
    if($db->num_rows($query) > 0)
    {
        while($row = $db->fetch_array($query))
        {
            $query2 = $db->simple_select('posts', '*', "pid='{$row['firstpost']}'");
            $row2 = $db->fetch_array($query2);
            
            $date = my_date($mybb->settings['dateformat'], $row2['dateline'], "", 1);
            $time = my_date($mybb->settings['timeformat'], $row2['dateline'], "", 1);

            $options = array(
                            'allow_html' => 'no',
                            'filter_badwords' => 'yes',
                            'allow_mycode' => 'yes',
                            'allow_smilies' => 'yes',
                            'nl2br' => 'yes',
                            'me_username' => 'yes'
                            );
            $message = $parser->parse_message($row2['message'], $options);
            
            echo("<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['subject']}</a> -
                Posted: {$date} {$time} by <a href=\"{$forumpath}member.php?action=profile&uid={$row2['uid']}\">{$row2['username']}</a><br />");
            echo("{$message}<br /><br />");
            echo("Replies (<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['replies']}</a>)<br /><hr />");
        }
    }
    else
    {
        echo 'Nothing to display.';
    }

?>
Got it working had to remove TABLE_PREFIX or something like that
(2009-06-11, 10:19 PM)Haruo Wrote: [ -> ]Got it working had to remove TABLE_PREFIX or something like that

Yes, because this was written for MyBB 1.2, and TABLE_PREFIX was removed in 1.4.
(2009-06-05, 10:01 AM)zoog Wrote: [ -> ]What I'm looking for is a change so I can specify a specific post id so only that post (may it be the first, the 8th or the 312th) will be shown in the output.

Anyone else has any ideas how to do this? It basicly needs to fetch a single post and show it. It would really help me a lot.

Really, I love this script. I'm running several websites displaying different categories of news depending on which tag it has in the subjectline and also using the forum as some sort of CMS for static front-end pages, it's really awesome! I hope someone knows how to point to a single post using the code Smile
thats in $query2 but it will only show one post if you change {$row['firstpost']} to your post ID
(2009-06-18, 05:12 PM)bombo Wrote: [ -> ]thats in $query2 but it will only show one post if you change {$row['firstpost']} to your post ID

Thanks, that's helps a bit. Still not doing what it's supposed to do though. I have a test forum category with two topics in them.

If I change the "firstpost" part with a post id it simply displays all the threads in the forum specified in the script without the actual content of the first posts. So it shows the title etc. but no post content at all.

If I change the code pid={$row['firstpost']} to pid=['741'] (the post id) it displays the two two threads I use to test, with subject line for both threads, but both the messages are the same (which is the content of post 741). So it's basicly pasting the same message in all the threads the scripts finds in the specified forum ID.

So it seems that the script should stop looking at all threads in a specific forum and should stop when 1 post is retreived. Unfortunately I cannot do this by changing $limit variable because there are also other things being pulled out of the forum on the same page at the same time which must not be limited to displaying 1 item.
i think i don't understand what you want
I'll try to explain it a bit better Smile

Currently I use this news script for several news pages like it was meant to be. But I also use the script for filling up static content pages on my website.

For example: I have two webpages, one is page1.php and the other is page2.php. The first one pulls it's content from forum id 1. The second one from forum id 2. Both these forums are located in a hidden category in the MyBB forum. In the forum with id 1 I make 1 thread with 1 post which is filled with the content I want to show on the static page called page1.php. For page2.php I make another forum in this hidden section and also make 1 thread with 1 post filled with the content for page2.php. In the page1.php and page2.php files I set the forum id corresponding to the one that has the content for that particular page. Eventually, for every static page I have on my website I have a hidden forum with 1 thread and 1 post with the content of the individual pages.

Since I have several websites pulling this static content from the hidden part of the forum I'm getting more and more forum id's because every single page needs to pull it's info from a seperate from id because this news script code is made to pull info from forum id's instead of pulling specific post id's. Since the amount of forum id's hogs down performance (also if you enable to drop down quick select box thingy for browsing the forum) I'd like to minimize the number of forums. Especially because I'll be expanding even more in the future.

So what I'm trying to accomplish is that I need only 1 forum id with 1 thread for a whole bunch of static pages. In this 1 thread I make several posts, each post filled with the content for a specific static page, and in the script code of these static pages I tell them to look for a specific post so that they show the correct content for that particular page.

Please let me know if it's still unclear.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33