Codice PHP:
// Questo sricpt si trova nella pagina chiamata topics.php nella root principale, dovrebbero visualizzarsi gli ultimi topics del forum (in questo caso in una pagina esterna al forum)!
<?
include("get_posts_EXT.php");
$root_forum = $_SERVER['DOCUMENT_ROOT'].'/forum/';
get_posts('last','DESC',20);
?>
// Questa è la pagina get_post_EXT.php
<?php
function get_posts($mode='last', $ord='DESC', $limit=5)
{
global $root_forum;
include( $root_forum . 'config.php');
switch( $mode )
{
case 'last':
$order = 'topic_last_post_id ' .$ord . ' LIMIT ' . $limit; // ultimi inseriti
break;
case 'replies':
$order = 'topic_replies ' .$ord . ' LIMIT ' . $limit; // i più frequentati
break;
case 'views':
$order = 'topic_views ' .$ord . ' LIMIT ' . $limit; // i più visti
break;
case 'rand':
$order = 'RAND() LIMIT ' . $limit; // casuali
break;
default:
$order = 'topic_last_post_id DESC LIMIT ' . $limit; //default ultimi inseriti
break;
}
$access = mysql_connect($dbhost, $dbuser, $dbpasswd)
or die("Could not establish connection: " . mysql_error());
$db = mysql_select_db($dbname,$acces) or die ("Could not connect to database.
\n");
$sql="SELECT t.topic_id,t.topic_title, t.topic_last_post_id, p.post_time, u.username
FROM phpbb_topics t, phpbb_topics u, phpbb_posts p, phpbb_forums f
WHERE t.topic_last_post_id=p.post_id AND u.user_id=p.poster_id
AND f.forum_id=t.forum_id AND f.auth_view=0
ORDER BY $order";
if ( !($result = mysql_query($sql)) )
{
die("Could not obtain post information.");
}
while( $row = mysql_fetch_array($result) )
{
echo("<a href=\"" . $root_forum . "viewtopic.php?t=" . $row["topic_id"] ."\" title=\"\">" . $row["topic_title"] . "</a>
");
}
mysql_free_result();
mysql_close($db);
}
?>
// Questo è il contenuto del file config.php
<?php
// phpBB 2.x auto-generated config file
// Do not change anything in this file!
$dbms = 'mysql';
$dbhost = 'xxxx';
$dbname = 'xxxx';
$dbuser = 'xxxxxx';
$dbpasswd = 'xxxxx';
$table_prefix = 'phpbb_';
define('PHPBB_INSTALLED', true);
?>
// E questo è il fottutissimo errore!!
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /mnt/raid1-01/home/cellutop/cellulartopic.com/htdocs/get_posts_EXT.php on line 29
Could not connect to database.