Отрефакторил (+/-)
function LastNotes($switch = 'F', $lmt = 5) {
if ($switch == 'F' && intval($lmt) > 0) {
$out = '<div class="bmenu">Последние <b>'. $lmt .'</b> тем форума</div>';
$sql = "SELECT id, text FROM forum WHERE type = 't' ORDER BY time DESC LIMIT $lmt";
} elseif ($switch == 'L' && intval($lmt) > 0) {
$out = '<div class="bmenu">Последние <b>'. $lmt .'</b> статей библиотеки</div>';
$sql = "SELECT id, name, count_views, count_comments FROM library_texts
WHERE premod = 1 ORDER BY time DESC LIMIT $lmt";
} else {
return false;
}
$res = mysql_query($sql) or die (mysql_error());
$i = 0;
while ($row = mysql_fetch_assoc($res)) {
if ($switch == 'F') {
$out .= ($i % 2 ? '<div class="list2">' : '<div class="list1">') .
'<a href="/forum/?id='. $row['id'] .'">'. $row['text'] .'</a></div>';
} elseif ($switch == 'L') {
$color_views = ($row['count_views'] > 0 ? 'green' : 'red');
$color_comments = ($row['count_comments'] > 0 ? 'green' : 'red');
$out .= ($i % 2 ? '<div class="list2">' : '<div class="list1">') .
'<a href="/library/?id='. $row['id'] .'">'. $row['name'] .'</a>' .
'<div class="topmenu">просмотры: <span style="color:'. $color_views .'">'.
$row['count_views'] .'</span> комментарии: <span style="color:'. $color_comments .'">'.
$row['count_comments'] .'</span></div></div>';
}
$i++;
}
return $out;
}
echo LastNotes('L'); //Последние 5 статей библиотеки
echo LastNotes('F', 10); //Последние 10 тем форума