MyBB Community Forums

Full Version: Recent Posts
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Im making a little script to output the last 4 recent posts.

<html>
<head>
<style type="text/css">
div.row1{background-color: blue;}
div.row2{background-color: pink;}
</style>
</head>
<?php
$forumpath = "./forum/"; // Path to your forums root directory (with trailing slash)
require $forumpath."inc/config.php";

mysql_select_db($config['database'], mysql_connect($config['hostname'], $config['username'], $config['password']));

$query = mysql_query( 
"SELECT `mybb_threads`.`tid`, `mybb_threads`.`subject`
FROM mybb_threads
WHERE (`mybb_threads`.`visible` =1)
ORDER BY `mybb_threads`.`tid` DESC
LIMIT 4" 
)
or die(mysql_error());
echo "cheese";
$recentpostsinc = 1 ;
while($recentposts = mysql_fetch_assoc($query))
{

if ($recentpostsinc = 3 )
{
$recentpostsinc = 1 ;
} 
echo "<div class=\"row".$recentpostsinc."\"><a href=\"./forum/showthread.php?tid=".$recentposts['tid']."\" target=\"_blank\">".$recentposts['subject']."</a></div>";
$recentpostsinc++ ;
}
?>
</html>


outputs

<html>
<head>
<style type="text/css">
div.row1{background-color: blue;}
div.row2{background-color: pink;}
</style>
</head>


cheese<div class="row1"><a href="./forum/showthread.php?tid=187" target="_blank">All my Habbo alts</a></div><div class="row1"><a href="./forum/showthread.php?tid=186" target="_blank">My paint art</a></div><div class="row1"><a href="./forum/showthread.php?tid=183" target="_blank">Rip a record</a></div><div class="row1"><a href="./forum/showthread.php?tid=182" target="_blank">Template FAQ</a></div>

</html>

Why is it not incrementing the row numbers?
Heloo there

use this code

<html>
<head>
<style type="text/css">
div.row1{background-color: blue;}
div.row2{background-color: pink;}
</style>
</head>
<?php
require "./inc/config.php";
require "./inc/init.php";

$db->query($config['database'], mysql_connect($config['hostname'], $config['username'], $config['password']));

$query = $db->query("SELECT tid,subject FROM ".TABLE_PREFIX."threads WHERE visible ='1' ORDER BY tid DESC LIMIT 0,4") or die(mysql_error());
echo "cheese";
$recentpostsinc = 1 ;
while($recentposts = mysql_fetch_assoc($query))
{
/**if ($recentpostsinc = 3 )
{
$recentpostsinc = 1 ;
} */ //why this 
echo "<div class=\"trow1\"> $recentpostsinc <a href=\"./forum/showthread.php?tid=".$recentposts['tid']."\" target=\"_blank\">".$recentposts['subject']."</a></div>";
$recentpostsinc++ ;
}
?>
</html>

 

I have modified the queries a little.
I have remove uneeded pieces of code.
e.g
if ($recentpostsinc = 3 )
{
$recentpostsinc = 1 ;
} 

and i have fixed the echo, so that numbers appear beside each entry

regards
i had that code, so it would allow me to have two rows which would repeat...

text (row 1)
text (row 2)
text (row 1)
text (row 2)
text (row 1)
text (row 2)

alright ! anyway did my fix helped u Confused :$.



no, it just gave the same output.
never mind, i did it. I needed a == at the for.