IPB - последни теми
Като си направите форум много често си задавате въпроса как ще стане да се показват последните теми от форума... еми, ето така:


<?php



/***
Invision Power Board - Last Topics System
like www.bgdev.org with category, forum name and reply counter
***/



//Author: Vasil Antonov

//Email: vasko@bgdev.org

//Date: 24.07.2004





//------------------------------

//Edit this parameters:



//MySQL server adress

$host="";



//Username

$user="";



//Password

$pass="";



//Database

$db="";



//Table

$table_topics="ibf_topics";
$table_forums="ibf_forums";
$table_category="ibf_categories";



//Show last x posts

$laforums="10";



//-------------------------- END





//------------------------------

//Don't edit !



$link=mysql_connect($host, $user, $pass);

$db=mysql_select_db($db);

$query="select * from $table_topics order by start_date desc limit 0,$laforums";

$result=mysql_query($query, $link);

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

$query1="select * from $table_forums where id='$row[forum_id]'";
$result1=mysql_query($query1, $link);
$row1=mysql_fetch_array($result1);



/* English info about $forum_name=$row1[name];
This variable must be add below,
if you want to show the forum name in the page.
*/

/* Bulgarian info about $forum_name=$row1[name];
Тази променлива трябва да се вмъкне по-долу,
ако искате да се покаже името на форума в страницата.
*/

$forum_name=$row1[name];



$category_id=$row1[category];

$query2="select * from $table_categories where id='$category_id'";
$result2=mysql_query($query2, $link);
$row2=mysql_fetch_array($result2);
$cat=$row2[name];

if ( $row[posts]==0 ){
echo "<a href='http://www.domain.com/index.php?showtopic=$row[0]'>$cat: $row[title]</a><br>";
}
else {
echo "<a href='http://www.domain.com/index.php?showtopic=$row[0]'>$cat: $row[title]</a> ($row[posts])<br>";
}

}



//-------------------------- END



?>


ИЛИ

<?php

/*
Edit parameters below
*/
$sqlHost = "localhost";
$sqlUser = "";
$sqlPassword = "";
$sqlDatabase = "board";
$sqlTablePrefix = "ib";
$sqlTopics = 5;

$htmlPattern = '<a href="http://www.domain.com/board/index.php?showtopic={{tid}}" target="_blank">{{title}} <small>(in {{forum_name}}, {{category_name}}; {{posts}} posts)</small></a><br />';


/*
Please, do not edit this
*/
$sqlQuery = "
SELECT
`prefix_topics`.*,
`prefix_forums`.`name` AS `forum_name`,
`prefix_categories`.`name` AS `category_name`

FROM `prefix_topics`, `prefix_forums`, `prefix_categories`

WHERE
`prefix_topics`.`forum_id` = `prefix_forums`.`id`
AND
`prefix_forums`.`category` = `prefix_categories`.`id`

ORDER BY `prefix_topics`.`start_date` DESC

LIMIT 0, " . $sqlTopics;


$sqlLink = @mysql_connect($sqlHost, $sqlUser, $sqlPassword, true);
if ($sqlLink === false) {
trigger_error("Could not connect to SQL host on `" . htmlspecialchars($sqlHost) . "`", E_USER_ERROR);
}

if (@mysql_select_db($sqlDatabase, $sqlLink) === false) {
trigger_error("Could not select database `" . htmlspecialchars($sqlDatabase) . "` on SQL host `" . htmlspecialchars($sqlHost) . "`", E_USER_ERROR);
}

$sqlResult = @mysql_query(str_replace("prefix_", $sqlTablePrefix . "_", $sqlQuery), $sqlLink);
if ($sqlResult === false) {
trigger_error("You have error in your query; database `" . htmlspecialchars($sqlDatabase) . "`; SQL host `" . htmlspecialchars($sqlHost) . "`", E_USER_NOTICE);
}

$topics = array();
while ($row = @mysql_fetch_array($sqlResult, MYSQL_ASSOC)) {
if (empty($row)) {
continue;
}
$topics[] = $row;
}

if (!empty($topics)) {

$pattern = "/\{\{([a-zA-Z0-9_]+)\}\}/i";

foreach ($topics as $topic) {

$htmlCode = $htmlPattern;
$iterate = 0;

while (preg_match($pattern, $htmlCode, $reg)) {

$strReplace = isset($topic[$reg[1>) ? $topic[$reg[1> : null;

$htmlCode = preg_replace($pattern, $strReplace, $htmlCode, 1);

if (++$iterate > 25) { break; }
}

echo $htmlCode;

}

} else {
trigger_error("No topics; database `" . htmlspecialchars($sqlDatabase) . "`; SQL host `" . htmlspecialchars($sqlHost) . "`", E_USER_NOTICE);
}

mysql_close($sqlLink);

?>


/ Трябва да сте регистриран за да напишете коментар /