Код:
function getLastPosts($topicNum) {
$sql = "SELECT Subdiv_ID FROM Forum_subdiv WHERE Subdiv_enabled = 1 AND Subdiv_ID NOT IN (8, 9, 25, 30)";
$res = mysql_query($sql);
while($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
$topic_array[] = "select Subdiv_ID, Topic_ID, Topic_subject, Topic_creator_name, Topic_replies, DATE_FORMAT(Topic_lastreply, '%d.%m %H:%i') AS Lastreply, Topic_lastreply from Forum_topics".$row['Subdiv_ID'];
}
mysql_free_result($res);
$sql_string = implode(' UNION ', $topic_array)." ORDER BY Topic_lastreply DESC LIMIT ".$topicNum;
$res = mysql_query($sql_string);
while($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
$result .= "<li>— <a href='/friends/forum/?Subdiv_ID=".$row['Subdiv_ID']."&Topic_ID=".$row['Topic_ID']."#".$row['Topic_replies']."'>".$row['Topic_subject']."</a> <span>(".$row['Lastreply'].")</span></li>";
}
mysql_free_result($res);
return $result;
}