MyBB Community Forums

Full Version: Latest news help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hey, I'm using a script that someone else made, and I was wondering if someone could modify it so it would display the post as well as the subject.

Thanks (here's the code)[/code]

<?php
/** Config **/
$dbhost = "xxx";
$dbuser = "xxx";
$dbpassword = "xxx";
$dbdatabase = "xxx";
$prefix = "mybb_"; //Databaseprefix

$url = "xxx"; // URL to the board
$viewable_forums = "xx"; //viewable forums - seperate with coma , (for examble "xx")
$limit = "xx"; // How many topics we want to see?
$length = "xx"; // length of the subject (0 ist full length)
/** End of config **/

// We connect to the database
$db = mysql_connect($dbhost,$dbuser,$dbpassword) or die ("Verbindung fehlgeschlagen");
mysql_select_db($dbdatabase,$db);
$viewable_forums = str_replace(","," OR fid=",$viewable_forums);

echo "";
// username= author // replies = answers
$query = mysql_query ("SELECT subject,tid,replies,fid FROM ".$prefix."threads WHERE visible='1' AND fid=".$viewable_forums." ORDER BY tid DESC LIMIT 0,".$limit."");
while ($newest_threads = mysql_fetch_array($query))
{
    if ($length != 0)
    {
        if (strlen($newest_threads['subject']) > $length)
        {
            $newest_threads['subject'] = substr($newest_threads['subject'],0,$length) . "...";
        }
    } 
    echo "<h2 align=left><img src=img/newshead.png>".$newest_threads['subject']."  
- <a href=\"".$url."/showthread.php?tid=".$newest_threads['tid']."\" target=\"_blank\">Discuss!</a></h2><br />";
}
echo "<br />";
?>

*bump*
You just bumped a thread in the last 2 hours. Haven't you read our posting guidelines yet?
$query = mysql_query ("SELECT t.subject, t.tid, t.replies, t.fid, p.message FROM ".$prefix."threads t LEFT JOIN ".$prefix."posts p ON (p.pid=t.firstpost) WHERE t.visible='1' AND t.fid=".$viewable_forums." ORDER BY t.tid DESC LIMIT 0,".$limit."");
You can use something like that as your query, then use $newest_threads['message'] to get the message under the while loop.
You should be able to figure out where to put it. As I don't know where you want it.

Please don't bump your thread just to get it up one post in the forum display. We are online when we are, a bump can't change the fact that we aren't payed and we aren't sitting at our computers 24 hours a day, although sometimes it feels like it.

Merging bump post

Cheers,
CraKteR.
Hey Crakter, thanks alot, and sorry for the bump post. I've been trying to do this for awhile, how can I use the str_replace feature in PHP with it?

I've tried this:
newest_threads['message'] = str_replace("e", "HAHA!", $newest_threads['message']); 

and it isn't appearing to replace e with HAHA!
$newest_threads['message'] = str_replace("e", "HAHA!", $newest_threads['message']);

Should work.
Heh. It isn't working. I forgot to post the

$

part. Sorry.
are you sure $newest_threads['message'] holds t/he contents of the message? maybe you misspelled something
It doesn't work? How do you know? Have you added so it outputs the message?

Cheers,
CraKteR.
Here is the code, and the str_replace string isn't working.

<?php
$newest_threads['message'] = str_replace("e", "HAHA!", $newest_threads['message']); 
/** Config **/
$dbhost = "xxx";
$dbuser = "xxx";
$dbpassword = "xxx";
$dbdatabase = "xxx";
$prefix = "mybb_"; //Databaseprefix

$url = "xxx"; // URL to the board
$viewable_forums = "xx"; //viewable forums - seperate with coma , (for examble "xx")
$limit = "xx"; // How many topics we want to see?
$length = "xx"; // length of the subject (0 ist full length)
/** End of config **/

// We connect to the database
$db = mysql_connect($dbhost,$dbuser,$dbpassword) or die ("Verbindung fehlgeschlagen");
mysql_select_db($dbdatabase,$db);
$viewable_forums = str_replace(","," OR fid=",$viewable_forums);

echo "";
// username= author // replies = answers
$query = mysql_query ("SELECT subject,tid,replies,fid FROM ".$prefix."threads WHERE visible='1' AND fid=".$viewable_forums." ORDER BY tid DESC LIMIT 0,".$limit."");
while ($newest_threads = mysql_fetch_array($query))
{
    if ($length != 0)
    {
        if (strlen($newest_threads['subject']) > $length)
        {
            $newest_threads['subject'] = substr($newest_threads['subject'],0,$length) . "...";
        }
    }
    echo "<h2 align=left><img src=img/newshead.png>".$newest_threads['subject']."  
- <a href=\"".$url."/showthread.php?tid=".$newest_threads['tid']."\" target=\"_blank\">Discuss!</a></h2><br />";
}
echo "<br />";
?>
You need:
$newest_threads['message'] = str_replace("e", "HAHA!", $newest_threads['message']); 
Under your while function. And you haven't even changed your query with my new one. So it won't work.

Now we're going to have a nice Christmas. So bye.

Cheers,
CraKteR.
Pages: 1 2