[SOLVED] Stand-alone Latest Topics script!

This forum is now closed as part of retiring phpBB2
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Suspiria
Registered User
Posts: 60
Joined: Fri Apr 18, 2003 11:46 am
Location: Utopia

[SOLVED] Stand-alone Latest Topics script!

Post by Suspiria » Wed Apr 30, 2003 10:04 am

SOLVED by Shantra

I have searched the forums but havent found anything about it.

I am looking for a stand-alone PHP script that dont have to include any files to work, and that dont have a "user interface". It should show the latest topics: Topic, Num Posts, Num Views and Started By
Last edited by Suspiria on Thu May 08, 2003 3:06 pm, edited 3 times in total.
SUSPIRIA The Only Thing More Terrifying Than The Last 12 Minutes Of This Film Are The First 92

User avatar
Tyz
Registered User
Posts: 4
Joined: Wed Apr 30, 2003 2:22 pm
Location: Holland, lwrden

me 2

Post by Tyz » Wed Apr 30, 2003 2:28 pm

Im searching for something like that aswell.

I want to display the latest 5 or 8 topics/posts on my homepage (on a other page then phpbb forum).

Suspiria
Registered User
Posts: 60
Joined: Fri Apr 18, 2003 11:46 am
Location: Utopia

Post by Suspiria » Wed Apr 30, 2003 2:39 pm

Tyz,

Have you tried the ones in the Mod section? http://www.phpbb.com/phpBB/catdb.php?cat=5

Maybe they fits your need
SUSPIRIA The Only Thing More Terrifying Than The Last 12 Minutes Of This Film Are The First 92

Rikki
Registered User
Posts: 45
Joined: Tue Jun 04, 2002 11:36 am
Location: Glasgow

Post by Rikki » Wed Apr 30, 2003 5:14 pm

Here you go :

Code: Select all

<?

include('config.php');				//	Config file holds our password and other details.

$dbname = "forum";
$tb = "phpbb_topics";

$connect = mysql_connect($dbhost, $dbuser, $dbpasswd);

if (!$connect) { 	echo "Forum Offline"; return; }			//	IF DATABASE DEAD

mysql_select_db($dbname);

    $query = mysql_query("SELECT * FROM $tb ORDER BY topic_id DESC LIMIT 5");

while ($news = mysql_fetch_array($query)) {		// While there are records in the table display them via loop

print "<A HREF=phpBB/viewtopic.php?t=";
print $news[topic_id];
//print "&forum=";
//print $news[forum_id];
print ">";

$topic_title = stripslashes($news[topic_title]);	// Set variabe

if (strlen($topic_title) > 30) {			// If length of variable is under 30 do loop

	$i = 0;
	
	while ($i < 30) {				// This loop finds the last space and notes
		if ($topic_title{$i} == " ") { $ii = $i; }	// its location.
		$i++;
		}

	$topic_title = substr($news[topic_title], 0, $ii);	// Then truncates the string for you.
}

print $topic_title;

print "...";

print "</A><BR>";
       
}

?>
Seen in action on my site www.strathycruise.com

R.

User avatar
drathbun
Former Team Member
Posts: 12204
Joined: Thu Jun 06, 2002 3:51 pm
Location: TOPICS_TABLE
Contact:

Re: Stand-alone Latest Topics script!

Post by drathbun » Wed Apr 30, 2003 6:28 pm

Suspiria wrote: I am looking for a stand-alone PHP script that dont have to include any files to work...
Rikki wrote:

Code: Select all

<? 

include('config.php');

What's wrong with this picture? :-D

Seriously, it's best to include at least the config. Otherwise you have to hardcode your db and password in two places instead of one. But if you absolutely can't have any includes, simply put your specific db info into the code sample provided and you should be fine without the include of config.php. 8)

Dave
I blog about phpBB: phpBBDoctor blog
Still using phpbb2? So am I! Click below for details
Image

Rikki
Registered User
Posts: 45
Joined: Tue Jun 04, 2002 11:36 am
Location: Glasgow

Post by Rikki » Wed Apr 30, 2003 6:52 pm

Cheeky kahts.

Code: Select all

<?

$dbhost = "localhost";
$dbuser = "xxx";
$dbpass = "xxx";

?>
Is the only thing in config.php

Copy that into the above code and it will work fine

stClem
Registered User
Posts: 1
Joined: Wed Apr 30, 2003 7:53 pm

Post by stClem » Wed Apr 30, 2003 7:58 pm

when i klick on the link to the last topic, the site whit the new topic open in the same window as the topics. want them to open on top, like html script target="_top"

help?

Rikki
Registered User
Posts: 45
Joined: Tue Jun 04, 2002 11:36 am
Location: Glasgow

Post by Rikki » Wed Apr 30, 2003 10:24 pm

Stick that in the part that says :

Code: Select all

print "<A HREF=phpBB/viewtopic.php?t="; 
print $news[topic_id]; 
//print "&forum="; 
//print $news[forum_id]; 
print " target='_top'>"; 

shim007
Registered User
Posts: 7
Joined: Wed Feb 19, 2003 12:42 am

Post by shim007 » Thu May 01, 2003 7:23 am

hello,

do i put the script in my 'forum' directory, site root directory, or does it go in, for instance, my index.php page?

thanks in advance.

Rikki
Registered User
Posts: 45
Joined: Tue Jun 04, 2002 11:36 am
Location: Glasgow

Post by Rikki » Thu May 01, 2003 3:14 pm

You can place it whereever you like as it doesnt not need access to the phpBB folder. It access the database directly.

Just place it in a PHP script (we use it in main.php) and it should work fine.

R.

shim007
Registered User
Posts: 7
Joined: Wed Feb 19, 2003 12:42 am

Post by shim007 » Thu May 01, 2003 7:17 pm

Rikki wrote: You can place it whereever you like as it doesnt not need access to the phpBB folder. It access the database directly.

Just place it in a PHP script (we use it in main.php) and it should work fine.

R.



thank you :P

Shantra
Registered User
Posts: 59
Joined: Thu Jul 05, 2001 8:42 pm
Location: Norway

Post by Shantra » Sat May 03, 2003 2:25 pm

Unfortunately that code dont fit Suspirias or my needs.

The following code would do the job.
Shows: Title - Replies - Views - Posted by

Code: Select all

<?php
/***************************************************************************
 *
 *   Mod Title: PHP Latest Topics
 *   Mod Version: 1.0.0
 *   Author: Erik Holm, eholm_oslo@yahoo.no
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *
 ***************************************************************************/

// ***** Config Start *****
$dbname = "forums"; // Database name.
$tbtopics = "phpbb_topics"; // Topics table name.
$tbusers = "phpbb_users"; // Users table name.
$forumpath = "phpbb"; // Path to forums. Do NOT end with /
$numtopics = "10"; // Number of topic rows
// ***** Config End *****

include($forumpath . '/config.php'); // Config file holds password and other details. 

$connect = mysql_connect($dbhost, $dbuser, $dbpasswd); 
if (!$connect) { echo "Can't connect to forums database"; return; } 
mysql_select_db($dbname); 
$query = mysql_query("SELECT topic_id, topic_title, topic_poster, topic_replies, topic_views, user_id, username FROM $tbtopics LEFT JOIN $tbusers ON $tbtopics.topic_poster=$tbusers.user_id WHERE topic_status = 0 ORDER BY topic_id DESC LIMIT $numtopics"); 

echo "<table width=\"500\" border=\"1\" cellspacing=\"0\" cellpadding=\"4\">";
echo "<tr><td width=\"100%\"align=\"center\">";
echo "Topic";
echo "</td><td align=\"center\">";
echo "Replies";
echo "</td><td align=\"center\">";
echo "Views";
echo "</td><td align=\"center\">";
echo "Posted by";
echo "</td></tr>";

while ($row = mysql_fetch_array($query)) 
{ 

$topic_title = stripslashes($row['topic_title']);
$topic_poster = stripslashes($row['username']);
$topic_poster_id = $row['topic_poster'];

echo "<tr><td >";
echo "<a href=\"" . $forumpath . "/viewtopic.php?t=" . $row['topic_id'] . "\">" . $topic_title . "</a>";
echo "</td><td align=\"right\">";
echo $row['topic_replies'];		
echo "</td><td align=\"right\">";
echo $row['topic_views'];	
echo "</td><td >";
if ($topic_poster_id == -1) // Check if poster is guest or member.
{ 
     echo "Guest";
}
else
{
     echo "<a href=\"" . $forumpath . "/profile.php?mode=viewprofile&u=" . $row['topic_poster'] . "\">" . $topic_poster . "</a>";
}
echo "</td></tr>";

} 
echo "</table>";
?> 
I have sent this code for MOD inclusion!
Last edited by Shantra on Fri May 09, 2003 12:25 am, edited 2 times in total.

Suspiria
Registered User
Posts: 60
Joined: Fri Apr 18, 2003 11:46 am
Location: Utopia

Post by Suspiria » Sat May 03, 2003 10:40 pm

Thanks Rikki and Shantra,

Your code Shantra works perfectly for my needs :D
SUSPIRIA The Only Thing More Terrifying Than The Last 12 Minutes Of This Film Are The First 92

Antony
Registered User
Posts: 529
Joined: Wed Feb 12, 2003 9:06 am

Post by Antony » Sat May 03, 2003 11:15 pm

Mine scrolls. :roll:

Code: Select all

<?php
// How Many Topics you want to display?
$topicnumber = 10;
// Scrolling towards up or down?
$scroll = "up";
// Change this to your phpBB path
$urlPath = "http://yourdomain.com/phpBB";

// Database Configuration (Where your phpBB config.php file is located
include 'http://yourdomain.com/config.php';

$table_topics = $table_prefix. "topics";
$table_forums = $table_prefix. "forums";
$table_posts = $table_prefix. "posts";
$table_users = $table_prefix. "users";
$link = mysql_connect("$dbhost", "$dbuser", "$dbpasswd") or die("Could not connect");
mysql_select_db("$dbname") or die("Could not select database");

$query = "SELECT t.topic_id, t.topic_title, t.topic_last_post_id, t.forum_id, p.post_id, p.poster_id, p.post_time, u.user_id, u.username
FROM $table_topics t, $table_forums f, $table_posts p, $table_users u
WHERE t.topic_id = p.topic_id AND 
f.forum_id = t.forum_id AND 
t.topic_status <> 2 AND 
p.post_id = t.topic_last_post_id AND 
p.poster_id = u.user_id
ORDER BY p.post_id DESC LIMIT $topicnumber";
$result = mysql_query($query) or die("Query failed");

print "<marquee id=\"recent_topics\" behavior=\"scroll\" direction=\"$scroll\" height=\"170\" scrolldelay=\"100\" scrollamount=\"2\" onMouseOver=\"document.all.recent_topics.stop()\" onMouseOut=\"document.all.recent_topics.start()\">
<table cellpadding='3' cellSpacing='2' width='350'>";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo  "<tr valign='top'><td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\"><font color=\"#FFCC00\"><b><a href=\"$urlPath/viewtopic.php?topic=$row[topic_id]&forum=$row[forum_id]\">" .
$row["topic_title"] .
"</a></td></font></b><td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\"><font color=\"#C0C0C0\"> by: <a href=\"$urlPath/profile.php?mode=viewprofile&u=$row[user_id]\">" .
$row["username"] .
"</td><td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\"><font color=\"#C0C0C0\">" .
date('F j, Y, g:i a', $row["post_time"]) .
"</td></tr></font>";
}
print "</table></marquee>";
mysql_free_result($result);
mysql_close($link);
?>
I've Been Banned!

Goemon
Registered User
Posts: 13
Joined: Fri May 02, 2003 1:14 pm

Post by Goemon » Sat May 03, 2003 11:29 pm

Hi Rikki,
a question about your code: how do I list only topics from a single forum (I.E.: forum_id is "9")?

Post Reply

Return to “[2.0.x] MOD Requests”