hi friends, i would like to make my webiste be integrated with mybb.
i would like to include login box and recent posts on websites home page.
iam using 1.2.2
could any one suggest me the latest code to do it. i studied the user submitted tutorials the integration . but i get a blank recent posts .so could any one suggest me the code.
Hello
Use this code to show the latest 5 forums' threads on your site.
//Connect to mybb db
mysql_connect("localhost", "username", "password") or die("Could not connect to MySQL");
mysql_select_db("db_name") or die("Could not connect to MySQL");
//query to get latest 5 threads
$query = mysql_query("
SELECT t.*, u.username
FROM mybb_threads t
LEFT JOIN mybb_users u ON (u.uid=t.uid)
WHERE 1=1 AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
ORDER BY t.lastpost DESC
LIMIT 0, 5"
);
$list = '';
while($fetch = mysql_fetch_array($query))
{
$list .= "<strong><a href=\"forums/showthread.php?tid={$fetch['tid']}\">".htmlspecialchars_uni($fetch['subject'])."</a></strong><br />";
}
//output
echo $list;
//MyBB htmlspecialchars function
function htmlspecialchars_uni($message)
{
$message = preg_replace("#&(?!\#[0-9]+;)#si", "&", $message); // Fix & but allow unicode
$message = str_replace("<","<",$message);
$message = str_replace(">",">",$message);
$message = str_replace("\"",""",$message);
$message = str_replace(" ", " ", $message);
return $message;
}
For the log in box, read
here
Isn't there a better way to connect to MySQL, using some king of mysterious MyBB function?
Oh, I see. You are trying to minimize loading time.
I used the PHP functions not MyBB's so that we don't have to include your external page in MyBB system and therefore it has to load many scripts and function etc...
regards
zaher1988 Wrote:I used the PHP functions not MyBB's so that we don't have to include your external page in MyBB system and therefore it has to load many scripts and function etc...
regards
when i tried to use the code i get the following error;
Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: YES) in C:\AppServ\www\xxxxxxx\login.php on line 81
Could not connect to MySQL
------------------------------
i started the page with following php code;
-----
<?php
define('IN_MYBB', 1);
$rel = "./forums/"; // The directory to your forum--relative to this file's location; include ending slash
chdir($rel);
require("./global.php");
?>
my root directory lets say xxxxxxxx;my forums is located at xxxxxxx/forums. i changed the mybb root folder name as forums. ;
please help me out to resolve the issue
thanks allot zaher,
it was nice code i modified little it is working. in my forums the no of posts are many and threads are less. i would like to post latest posts in the case of latest threads. how to change it. i tried to change the mybb_threads to mybb_posts it is showing errors. how to modify the query.i would like the display should look like[
attachment=5507] as displayed in portal.php of the mybb pleae help me out
Quote:<?php
//query to get latest 5 threads
$query = $db->query ("
SELECT t.*, u.username
FROM mybb_threads t
LEFT JOIN mybb_users u ON (u.uid=t.uid)
WHERE 1=1 AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
ORDER BY t.lastpost DESC
LIMIT 0, 10"
);
$list = '';
while($fetch = $db->fetch_array($query))
{
$list .= "<strong><a href=\"forums/showthread.php?tid={$fetch['tid']}\">".htmlspecialchars_uni($fetch['subject'])."</a></strong><br />";
}
//output
echo $list;
?>
Alright keep the code i have previously provided and just modify
$list .= "<strong><a href=\"forums/showthread.php?tid={$fetch['tid']}\">".htmlspecialchars_uni($fetch['subject'])."</a></strong><br />";
Replace it by
$list .= "<strong><a href=\"forums/showthread.php?tid={$fetch['tid']}\">".htmlspecialchars_uni($fetch['subject'])."</a></strong><br />";
$lastposter = "<a href=\"forums/member.php?action=profile&uid=".$fetch['uid']."\">{$fetch['username']}</a>";
$list .= "<i>Last post by</i>: {$lastposter}<br />";
Did you just want the html form? Or did you want it to show details of the user once they logged in too?