Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i want display latest thread on my main home page
#1
((Google Translation))

hello all

i want display latest "5" threads on my home page

forum dir --> "forum"

and i want make new file called " latest.php" to use it for display latest threads

I'm sorry because my English is bad


i used this code


<?php

   echo "<meta http-equiv='content-type' content='text/html; charset=utf-8' />";
  
//Connect to mybb db
chdir('forum'); // path to MyBB
define("IN_MYBB", 1);
require '/global.php';

mysql_set_charset('utf8');

//query to get latest 5 threads
$query = mysql_query("SELECT * FROM mybb_threads t LEFT JOIN mybb_users u ON (u.uid=t.uid) ORDER BY t.lastpost DESC LIMIT 0, 5");

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

    }
    //output
    //echo $list;

//MyBB htmlspecialchars function
function htmlspecialchars_uni($message)
{
    $message = preg_replace("#&(?!\#[0-9]+;)#si", "&amp;", $message); // Fix & but allow unicode
    $message = str_replace("<","<",$message);
    $message = str_replace(">",">",$message);
    $message = str_replace("\"","&quot;",$message);
    $message = str_replace("  ", "&nbsp;&nbsp;", $message);
    return $message;
}



echo "<marquee direction='right' scrollamount='3'>";
echo $list;
echo "</marquee></p> ";




?>


But show this messages

Fatal error: Cannot redeclare htmlspecialchars_uni() (previously declared in C:\wamp\www\latest.php:30) in C:\wamp\www\forum\inc\functions.php on line 4037


Please help me

Reply
#2
:oops: deleted
Reply
#3
This user has been denied support. This user has been denied support.
you can show the latest thread using portal mod
Reply
#4
You can try and use a sidebox plugin.
Reply
#5
just remove the function declaration in your file as MyBB is loading its version automatically when you include global.php
Lost interest, sold my sites, will browse here once in a while. It's been fun.
Reply
#6
when i change this

//Connect to mybb db
chdir('forum'); // path to MyBB
define("IN_MYBB", 1);
require '/global.php';

to

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

the file is working , But I want to use this code



chdir('forum');
define("IN_MYBB", 1);
require '/global.php';

and i don't know Where is the problem ?

please any one help me & fix this code or Give me another code to display the last 5 topics on external page
Reply
#7
i gave you the solution.
Lost interest, sold my sites, will browse here once in a while. It's been fun.
Reply
#8
(12-17-2011, 09:06 PM)pavemen Wrote: just remove the function declaration in your file as MyBB is loading its version automatically when you include global.php

(12-18-2011, 05:18 AM)pavemen Wrote: i gave you the solution.

please explain it , because i don't understand any thing Undecided
Reply
#9
^ he suggested to not use function htmlspecialchars_uni($message)

simple example :
<?php
define("IN_MYBB", 1);
require_once("./global.php"); // Change this if needed
$tlimit = 5; // How many titles you want

$query = $db->query("SELECT * FROM ".TABLE_PREFIX."threads ORDER BY `tid` DESC LIMIT $tlimit");
while($fetch = $db->fetch_array($query)){
echo '<a href="./showthread.php?tid='.$fetch['tid'].'">'.$fetch['subject'].'</a><br />' . "\n";
}
?>

if Arabic threads are not shown correctly then you have to use required encoding ..
Reply
#10
Finally succeeded

Thanks for all & special thanks to pavemen and ranjani

[Image: yMA97665.png]


<?php

define("IN_MYBB", 1);
require_once("forum/global.php"); // Change this if needed
$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=\"forum/showthread.php?tid={$fetch['tid']}\" target=\"_blank\">".htmlspecialchars_uni($fetch['subject'])."</a></strong>";
        /*
		$poster = "<a href=\"forum/member.php?action=profile&uid=".$fetch['uid']."\">{$fetch['username']}</a>";
        $list .= "Created by: {$poster}  ";
        $list .= "<i>" .$fetch['replies']. " Replies</i>";
        $list .= "<i> , " .$fetch['views']. " Views</i>  ";
        $list .= " (<i>Last post by: " .$fetch['lastposter']. "</i>)<br /><hr width=\"50\"><br />";
        */
    }


//output

echo "<marquee direction='right' scrollamount='3'>";
echo $list;
echo "</marquee></p> ";

?>
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)