Jeszcze trochę przerobiłem ten skrypcik:) może komuś się przyda...
v.1.1
-Dodana Paginacja i zliczanie wszystkich newsów:)
demo:
http://studionik.pl/newsy.php
Kod: Zaznacz cały
<?php
include ('forum/config.php'); //folder w którym znajduje się skrypt forum
$forumid = '2'; // ID forum do pobierania newsow
mysql_connect('localhost',$dbuser,$dbpasswd);
mysql_select_db($dbname);
$display = 2; //ile newsów na stronie
if (isset($_GET['np'])) {
$num_pages = $_GET['np'];
} else {
$query = "SELECT COUNT(*) FROM `phpbb_topics` as temat, `phpbb_posts` as post WHERE temat.topic_first_post_id = post.post_id AND temat.forum_id = {$forumid} ORDER BY temat.topic_id ASC";
$result = mysql_query($query);
$row = mysql_fetch_array ($result, MYSQL_NUM);
$num_records = $row[0];
if ($num_records > $display) {
$num_pages = ceil ($num_records/$display);
} else {
$num_pages = 1;
}
}
if (isset($_GET['s'])) {
$start = $_GET['s'];
} else {
$start = 0;
}
$pyta=mysql_query("SELECT temat.topic_id, `topic_title`, `topic_replies`, `post_text`,`topic_time` FROM
`phpbb_topics` as temat, `phpbb_posts` as post WHERE temat.topic_first_post_id = post.post_id AND temat.forum_id = {$forumid} ORDER BY temat.topic_id DESC LIMIT $start, $display");
while($r=mysql_fetch_array($pyta)) {
$czas = date("d.m.Y",$r['topic_time']);
$tresc = str_replace('[','<',$r['post_text']);
$tresc = str_replace(']','>',$tresc);
$tresc = nl2br($tresc);
echo "[{$czas}] {$r['topic_title']}</br>{$tresc}
</br>
Komentarzy: {$r['topic_replies']} | <a href='http://twojadresforum/forum/viewtopic.php?t={$r['topic_id']}'>Zobacz komentarze / Skomentuj</a></br>";// komentarze-wpisz własny adres forum
}
echo '<center>';
if ($num_pages > 1) {
$current_page = ($start/$display) + 1;
if ($current_page != 1) {
echo '<a href="newsy.php?s=' . ($start - $display) . '&np=' . $num_pages . '"><span class="stron"><< Poprzednia</span></a> ';
}
for ($i = 1; $i <= $num_pages; $i++) {
if ($i !=$current_page) {
echo '<a href="newsy.php?s=' . (($display * ($i - 1))) .'&np=' .$num_pages . '"><span class="stron2">' . $i . '</span></a> ';
} else {
echo '<a href="newsy.php?s=' . (($display * ($i - 1))) .'&np=' .$num_pages . '"><span class="stron">' . $i . '</span></a> ';
}
}
if ($current_page !=$num_pages) {
echo '<a href="newsy.php?s=' . ($start + $display) .'&np=' . $num_pages .'"><span class="stron">Następna >></span></a>';
}
}
echo '</br>';
$query = "SELECT * FROM `phpbb_topics` as temat, `phpbb_posts` as post WHERE temat.topic_first_post_id = post.post_id AND temat.forum_id = {$forumid} ORDER BY temat.topic_id";
$result = mysql_query($query);
$ilo = mysql_num_rows($result);
echo '<span class="stron2">Ogólnie w naszej bazie mamy ' . $ilo . ' newsy.</span>';
echo '</center>';
?>
Widzicie błędy?? piszcie...
v 1.2 bedzie miała bbcode
teraz trzeba używać html...
zapraszam do dyskusji i składania propozycji dodania bbcode do skryptu:)