Page 1 of 3

[SOLVED] Stand-alone Latest Topics script!

Posted: Wed Apr 30, 2003 10:04 am
by Suspiria
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

me 2

Posted: Wed Apr 30, 2003 2:28 pm
by Tyz
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).

Posted: Wed Apr 30, 2003 2:39 pm
by Suspiria
Tyz,

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

Maybe they fits your need

Posted: Wed Apr 30, 2003 5:14 pm
by Rikki
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.

Re: Stand-alone Latest Topics script!

Posted: Wed Apr 30, 2003 6:28 pm
by drathbun
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

Posted: Wed Apr 30, 2003 6:52 pm
by Rikki
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

Posted: Wed Apr 30, 2003 7:58 pm
by stClem
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?

Posted: Wed Apr 30, 2003 10:24 pm
by Rikki
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'>"; 

Posted: Thu May 01, 2003 7:23 am
by shim007
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.

Posted: Thu May 01, 2003 3:14 pm
by Rikki
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.

Posted: Thu May 01, 2003 7:17 pm
by shim007
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

Posted: Sat May 03, 2003 2:25 pm
by Shantra
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!

Posted: Sat May 03, 2003 10:40 pm
by Suspiria
Thanks Rikki and Shantra,

Your code Shantra works perfectly for my needs :D

Posted: Sat May 03, 2003 11:15 pm
by Antony
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);
?>

Posted: Sat May 03, 2003 11:29 pm
by Goemon
Hi Rikki,
a question about your code: how do I list only topics from a single forum (I.E.: forum_id is "9")?