list last 5 post

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Ideas Centre
squeggie
Registered User
Posts: 31
Joined: Sun May 20, 2007 6:31 pm

list last 5 post

Post by squeggie »

I know you can do this with other forums like ipb.
I dont see a way to do this..
I have two sites and one of them is the forum, what i want to do is show users the last 5 posts in the category (ex. tutorials, inside that category i have forums) I want to show the last posted tutorials in the category of all the forums inside the tutorial category..

how can i do this..

i searched but couldnt find anything..

also another question..
i have a guests that will view my forum and I would also like to disable the WHO IS ONLINE and the STATISTICS so only registers users can view it.. how do i do that?

squeggie
Registered User
Posts: 31
Joined: Sun May 20, 2007 6:31 pm

Re: list last 5 post

Post by squeggie »

uhm anyone???

tommekemc
Registered User
Posts: 457
Joined: Wed May 14, 2008 6:36 pm
Location: Belgium
Contact:

Re: list last 5 post

Post by tommekemc »

You just need to use this code (if you run PHP)

connect.php:

Code: Select all

$connection = mysql_connect("localhost", "LOGIN NAME", "LOGIN PASS") or die(mysql_error());
mysql_select_db("DATABASE NAME", $connection) or die(mysql_error());

Code: Select all

require_once("connect.php");
$number=0;
$forumQ=mysql_query("SELECT topic_id, forum_id, topic_title
FROM phpbb_topics
WHERE topic_approved=1
LIMIT 5");
while($forumRow = mysql_fetch_row($forumQ)){
$number++;
echo $number."<a href=YOUR LINK TO THE FORUM/viewtopic.php?f=".$forumRow[1]."&t=".$forumRow[0].">".$forumRow[2]."</a><br>";
}
This will show the 5 last posts, NOT the 5 last posted items (replies don't count).
Make sure you connect to your database first, I suppose you know how to do that.
What you have to do for your other issue depends on your style.
You'll have to add this in: "root/styles/YOUR STYLENAME/template/index_body.html"

Code: Select all

/*------------------------------------------------------------------------------
don't show this part to bots and users not registered
------------------------------------------------------------------------------*/
<!-- IF not S_IS_BOT -->
<!-- IF S_USER_LOGGED_IN -->
//the style thing to show the stats and things like that
<!-- ENDIF -->
<!-- ENDIF -->
/*------------------------------------------------------------------------------
show this again
------------------------------------------------------------------------------*/
EDIT: bots could see the stats, so users too using the bots, fixed now :)
Last edited by tommekemc on Wed May 28, 2008 7:24 pm, edited 2 times in total.
my sig
my projects

images deleted because of the 6kb (wtf?) rule...

squeggie
Registered User
Posts: 31
Joined: Sun May 20, 2007 6:31 pm

Re: list last 5 post

Post by squeggie »

thankyou so much.

still a newbie at php but im learning..

will guests be able to see this?

tommekemc
Registered User
Posts: 457
Joined: Wed May 14, 2008 6:36 pm
Location: Belgium
Contact:

Re: list last 5 post

Post by tommekemc »

guests will see:
a link t toppic1, a link to toppic2,...
I edited the source a little.
since you don't know it very well.
allso added a connect.php:)
my sig
my projects

images deleted because of the 6kb (wtf?) rule...

lemmans
Registered User
Posts: 26
Joined: Tue May 20, 2008 10:01 pm

Re: list last 5 post

Post by lemmans »

hey.. where's the connect.php file?


either i'm too limited or this disscussion is hard to follow because i dont understand how to do it!!

lemmans
Registered User
Posts: 26
Joined: Tue May 20, 2008 10:01 pm

Re: list last 5 post

Post by lemmans »

¿? anyone??

User avatar
indecisive311
Registered User
Posts: 47
Joined: Tue Jan 17, 2006 12:52 am
Location: Richmond, VA
Contact:

Re: list last 5 post

Post by indecisive311 »

What he is saying is to create a connect.php file with the connection information in the first code block he posted. In his second code block, first line, he is calling that connect.php file. Its not necessary... but good for proper coding practice.

User avatar
indecisive311
Registered User
Posts: 47
Joined: Tue Jan 17, 2006 12:52 am
Location: Richmond, VA
Contact:

Re: list last 5 post

Post by indecisive311 »

p.s. you are missing a ; at the end of your $forumQ select statement line. :)

I'm also trying to implement this on my site. Your select statement doesn't return the latest topic posts. I modified your select statement a bit...

SELECT topic_id, forum_id, topic_title FROM phpbb_topics WHERE topic_approved=1 ORDER BY topic_last_post_time DESC LIMIT 5

lemmans
Registered User
Posts: 26
Joined: Tue May 20, 2008 10:01 pm

Re: list last 5 post

Post by lemmans »

ok i'll try to run this tomorrow since my eyes are red right now... a lot of studying and mocketing for one day... :geek:


cyu

lemmans
Registered User
Posts: 26
Joined: Tue May 20, 2008 10:01 pm

Re: list last 5 post

Post by lemmans »

like i said... the explanation is really difficult to follow... I've installed some of this things before but never had any difficulty, this is really hard to understand. Sorry. doubts:

1- I created the connect.php file. is that all the code it should have?
doesnt it go with a

Code: Select all

<?php
?>
2 - Where does the seconde code box goes?? or at least what is it for...
I tried putting it on the table i wanted the list to appear but when i loaded the page, only the code appeared.

3 -
Make sure you connect to your database first, I suppose you know how to do that.
No i dont...


4 - Where does the third code box goes?
What is it for?
Should I replace this "//the style thing to show the stats and things like that" text with something?



5 -
p.s. you are missing a ; at the end of your $forumQ select statement line. :)
where?

6 - Where does this go?
SELECT topic_id, forum_id, topic_title FROM phpbb_topics WHERE topic_approved=1 ORDER BY topic_last_post_time DESC LIMIT 5

User avatar
indecisive311
Registered User
Posts: 47
Joined: Tue Jan 17, 2006 12:52 am
Location: Richmond, VA
Contact:

Re: list last 5 post

Post by indecisive311 »

In your connect.php file your code should look like this... Where it says LOGIN NAME, LOGIN PASS, and DATABASE NAME, you will have to replace with the username, password, and db name for your database.

connect.php:

Code: Select all

<?
    $connection = mysql_connect("localhost", "LOGIN NAME", "LOGIN PASS") or die(mysql_error());
    mysql_select_db("DATABASE NAME", $connection) or die(mysql_error());
?>
If you don't know what your db info is you should be able to find it in your config.php file under "/forum/config.php" Copy the values for the variables $dbname, $dbuser, and $dbpasswd. Another way you could do this would be to require config.php like the code below and change the LOGIN NAME, LOGIN PASS, and DATABASE NAME to the variables I just listed. Otherwise just move on...

connect.php:

Code: Select all

<?
    require_once("/forum/config.php");
    $connection = mysql_connect("localhost", $dbuser, $dbpasswd) or die(mysql_error());
    mysql_select_db($dbname, $connection) or die(mysql_error());
?>

Put this wherever you want the posts to display... replace YOUR LINK TO THE FORUM with, the path to your forum (if your forum is in a folder called forum in the root of your site the it would be <a href="/forum/viewtopic.php...

Code: Select all

<?
    require_once("connect.php");
    $number=0;
    $forumQ=mysql_query("SELECT topic_id, forum_id, topic_title FROM phpbb_topics WHERE topic_approved=1 ORDER BY topic_last_post_time DESC LIMIT 5")
    while($forumRow = mysql_fetch_row($forumQ)){
        $number++;
        echo $number."<a href=YOUR LINK TO THE FORUM/viewtopic.php?f=".$forumRow[1]."&t=".$forumRow[0].">".$forumRow[2]."</a><br>";
    }
?>
Other notes: Yes, any php code needs to have <? ?> or <?php ?> around it.

tommekemc
Registered User
Posts: 457
Joined: Wed May 14, 2008 6:36 pm
Location: Belgium
Contact:

Re: list last 5 post

Post by tommekemc »

how you should show it, depends on your style.
I don't know where you would want to show this, but if it it in PHPBB, you should tell me your style.
Otherwise, just edit your page, make it .php extention (realy important!), and put it inside a table:
<table><tr><td><?php

CODE GOES HERE

?></td></tr></table>
my sig
my projects

images deleted because of the 6kb (wtf?) rule...

lemmans
Registered User
Posts: 26
Joined: Tue May 20, 2008 10:01 pm

Re: list last 5 post

Post by lemmans »

ok... cool...
i want to put it in www.faudi.com.ar, in the index page

where there is a * next to a text at the very top.

=)

tommekemc
Registered User
Posts: 457
Joined: Wed May 14, 2008 6:36 pm
Location: Belgium
Contact:

Re: list last 5 post

Post by tommekemc »

name the var an unusual name (but one you'll remind) and then add this in your overall header (or where-ever the * is)

Code: Select all

{NAME OF THE VAR}
that should do the trick :)
my sig
my projects

images deleted because of the 6kb (wtf?) rule...

Locked

Return to “[3.0.x] MOD Requests”