REGISTER or LOGIN to have the annoying ads removed.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Anyone know how too...
#1
Does anyone know how to have like, the latest 5 forum posts on the main site in MyBB?
I want to have the 5 latest forum posts to be displayed on my site, but I don't know how. Is this somehow possible in PHP or whateverTongue and does anyone know the exact code how to do it?

Site: http://www.spsource.net
Forum: http://forum.spsource.net

Thanks Wink
Reply
#2
PHP Code:
<?php
// DBNAME
$dbname "";
// USERNAME
$user "";
// PASSWORD
$password "";
// TABLE_PREFIX
$prefix "mybb_";
// FORUMROOT
$root "";
// Posts To Show
$max 5;

// Connect to db
$db mysql_connect("localhost",$user,$password) or die ("Failure!");  
mysql_select_db
($dbname,$db);

// Get Posts
$query mysql_query("SELECT * FROM ".$prefix."posts ORDER BY dateline DESC LIMIT 0,$max");
while(
$posts mysql_fetch_array($query))
{
    
$tid $posts['tid'];
    
$pid $posts['pid'];
    
$subject $posts['subject'];
    
$username $posts['username'];
    
$post .= $username." <a href=\"{$root}showthread.php?tid={$tid}&amp;pid={$pid}#pid={$pid}\">{$subject}</a><br />";
}
echo 
$post;
?>

Should get you started. Just fill in the dbname, user and password. If needed change the table prefix and others.
Reply
#3
Personally I think your best bet is to use javascript and the rss feed.

You can even do some great things with AJAX...lots of scripts are available at DynamicDrive.com

http://www.dynamicdrive.com/dynamicindex18/

Try those....very easy to implement.
Reply
#4
Thanks I used Lex-'s script and it works. Thank you! Smile
Is there also a way to put How many members are online?
Reply
#5
Kikkerkont Wrote:Thanks I used Lex-'s script and it works. Thank you! Smile
Is there also a way to put How many members are online?

Code:
// Get Online Members
$user_query = mysql_query("SELECT COUNT(uid) as users FROM ".$prefix."sessions WHERE uid!='0' ");
$users = mysql_fetch_array($user_query);
    
$count = $users['users'];
if($count == 1)
{
    $is = "is";
    $mem = "Member";
}
else
{
    $is = "are";
    $mem = "Members";
}

echo "There ".$is." ".$count." ".$mem." Online.";
Reply
#6
Sweet! You rock at PHP, I added you on msn if thats ok with you because you're really helpfull and I can use some more Php scripts. Tongue Wink
Reply
#7
Kikkerkont Wrote:Sweet! You rock at PHP, I added you on msn if thats ok with you because you're really helpfull and I can use some more Php scripts. Tongue Wink

If help is needed, just reply overhere =P I read this thread daily Wink
Reply
#8
^Ok. Smile

Can you please give me the code for a login form (username, pass) so users can login from out the site?

Thanks! Smile
Reply
#9
Kikkerkont Wrote:^Ok. Smile

Can you please give me the code for a login form (username, pass) so users can login from out the site?

Thanks! Smile

Code:
// START -- VARIABLES
$mybbdir = "";
$redirect = "../".$mybbdir."/index.php";
// END -- VARIABLES
define('IN_MYBB', 1);
chdir($mybbdir);
require_once "./global.php";

if($mybb->user['uid'] > 0)
{
    echo "Hey, ".$mybb->user['username']."<br>Thanks for logging in.";
}
else
{
    echo "<form action='$mybbdir/member.php' method='post'>";
    echo "Username: <input type='text' name='username' size='25' maxlength='30' /><br />";
    echo "Password: <input type='password' name='password' size='25' />";
    echo "<input type='hidden' name='action' value='do_login'>";
    echo "<input type='hidden' name='url' value='$redirect' />";
    echo "<input type='submit' class='submit' name='submit' value='Login' /></form><br>";
}

Just fill in your MyBB_Forum Dir into $mybbdir. And make sure that your cookies are set like

CookieDomain = .spsource.net
CookiePath = /

Before trying to log in, clear cookies/cache then open the file in your browser and try to log in.
Reply
#10
I tried making it but it doesn't seem to work.
I added <?php .. ?> to it, and edited it, but it doesn't work. Can you please give me the total code, the forum is on http://forum.spsource.net Smile thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)