Seite 1 von 1
die ersten 5 Beiträge aus einem Forum auf der INDEX Seite
Verfasst: 13.03.2006 16:33
von sandra-muc
In diesem Forum gibt es den Bereich Neuigkeiten. Dieser steht an erster Stelle. In meinem Forum soll es genau so sein. Nun möchte ich aber auf meiner INDEX Seite, die nichts mit dem Forum zu tun hat, Auszüge eben aus diesem Forenbereich haben (Neuigkeiten). Am besten die ersten 5 Beiträge. Kann mir da jemand weiterhelfen?
Ich hoffe ich habe mein Anliegen einigermaßen gut rübergebracht!
Sandra
Verfasst: 13.03.2006 20:56
von S2B
MODL:recent_topics
Der kann das.

Verfasst: 13.03.2006 21:37
von sandra-muc
Super, weist du vieleicht auch wie ich es hinbekomme das er immer den ersten Beitrag eines jeden Themas anzeigt?
Sandra
Verfasst: 13.03.2006 22:37
von S2B
Da muss man was am Query ändern:
Finden:
Code: Alles auswählen
$sql = "SELECT t.*, f.forum_id, f.forum_name, u.username AS first_poster, u.user_id AS first_poster_id, u2.username AS last_poster, u2.user_id AS last_poster_id, p.post_username AS first_poster_name, p2.post_username AS last_poster_name, p2.post_time
FROM ". $table_prefix ."topics t, ". $table_prefix ."forums f, ". $table_prefix ."users u, ". $table_prefix ."posts p, ". $table_prefix ."posts p2, ". $table_prefix ."users u2
WHERE $where_forums t.topic_poster = u.user_id AND f.forum_id = t.forum_id AND p.post_id = t.topic_first_post_id AND p2.post_id = t.topic_last_post_id AND u2.user_id = p2.poster_id
ORDER BY t.topic_last_post_id DESC LIMIT $topic_limit";
in der Zeile finden:
danach einfügen:
in der Zeile (s.o.) finden:
danach einfügen:
in der Zeile (s.o.) finden:
danach einfügen:
Ausgeben kannst du den Text dann folgendermaßen (in deiner Schleife):
Der Code ist ungetestet, sollte aber normal laufen... Allerdings wirst du dann ohne BBCode-Parser auskommen müssen, denn sonst wird es um einiges komplizierter.

Für das Löschen der BBCode-UID's gibt es einen Code in der viewtopic.php:
Dann sieht der Beitrag wenigstens ein bisschen besser aus. *g*
Wenn du noch irgendwelche Fragen haben solltest, frag einfach.

Verfasst: 10.04.2006 14:19
von sandra-muc
Frisch aus dem Urlaub zurück, frag ich einfach...
Ich habe jetzt den Code eingefügt.
Code: Alles auswählen
<?php
// ############ Edit below ########################################
$topic_length = '30'; // length of topic title
$topic_limit = '5'; // limit of displayed topics
$special_forums = '1'; // specify forums ('0' = no; '1' = yes)
$forum_ids = '2'; // IDs of forums; separate them with a comma
$config_path = '/'; // path to config.php
$root_path = '/'; // link path
// ############ Edit above ########################################
$path = dirname(__FILE__);
include_once($path.$config_path .'config.php');
mysql_connect($dbhost, $dbuser, $dbpasswd) OR die('Unable to select server.');
mysql_select_db($dbname) OR die('Unable to select database.');
// ############## output ##############
echo '<table width="100%" cellpadding="1" cellspacing="1" border="0" align="center">
<tr>
<th colspan="2">'. $topic_limit .' last topics</th>
</tr>';
// ############## output ##############
$where_forums = ( $special_forums == '0' ) ? '' : 't.forum_id IN ('. $forum_ids .') AND ';
$sql = "SELECT t.*, f.forum_id, f.forum_name, u.username AS first_poster, u.user_id AS first_poster_id, u2.username AS last_poster, u2.user_id AS last_poster_id, p.post_username AS first_poster_name, p2.post_username AS last_poster_name, p2.post_time, pt.post_text
FROM ". $table_prefix ."topics t, ". $table_prefix ."forums f, ". $table_prefix ."users u, ". $table_prefix ."posts p, ". $table_prefix ."posts p2, ". $table_prefix ."users u2, " . $table_prefix . "posts_text pt
WHERE $where_forums t.topic_poster = u.user_id AND f.forum_id = t.forum_id AND p.post_id = t.topic_first_post_id AND p2.post_id = t.topic_last_post_id AND u2.user_id = p2.poster_id AND pt.post_id = p.post_id
ORDER BY t.topic_last_post_id DESC LIMIT $topic_limit";
$result = mysql_query($sql);
if( !$result )
{
die('SQL Statement Error: '. mysql_error());
exit();
}
$line = array();
while( $row = mysql_fetch_array($result) )
{
$line[] = $row;
}
for( $i = 0; $i < count($line); $i++ )
{
$forum_id = $line[$i]['forum_id'];
$forum_url = $root_path .'viewforum.php?f='. $forum_id;
$topic_id = $line[$i]['topic_id'];
$topic_url = $root_path .'viewtopic.php?t='. $topic_id;
$topic_title = ( strlen($line[$i]['topic_title']) < $topic_length ) ? $line[$i]['topic_title'] : substr(stripslashes($line[$i]['topic_title']), 0, $topic_length) .'...';
$topic_type = ( $line[$i]['topic_type'] == '2' ) ? 'Announcement ': '';
$topic_type .= ( $line[$i]['topic_type'] == '3' ) ? 'Global Announcement ': '';
$topic_type .= ( $line[$i]['topic_type'] == '1' ) ? 'Sticky ': '';
$topic_type .= ( $line[$i]['topic_vote'] ) ? 'Poll ': '';
$views = $line[$i]['topic_views'];
$replies = $line[$i]['topic_replies'];
$first_time = date('d.m.Y', $line[$i]['topic_time']);
$first_author = ( $line[$i]['first_poster_id'] != '-1' ) ? '<a href="'. $root_path .'profile.php?mode=viewprofile&u='. $line[$i]['first_poster_id'] .'">'. $line[$i]['first_poster'] .'</a>' : ( ($line[$i]['first_poster_name'] != '' ) ? $line[$i]['first_poster_name'] : 'guest' );
$last_time = date('d.m.Y', $line[$i]['post_time']);
$last_author = ( $line[$i]['last_poster_id'] != '-1' ) ? $line[$i]['last_poster'] : ( ($line[$i]['last_poster_name'] != '' ) ? $line[$i]['last_poster_name'] : 'guest' );
$last_url = '<a href="'. $root_path .'viewtopic.php?p='. $line[$i]['topic_last_post_id'] .'#'. $line[$i]['topic_last_post_id'] .'">'. $last_author .'</a>';
// ############## output ##############
echo '<tr>
<td valign="top" nowrap="nowrap">'. $topic_type .'<a href="'. $topic_url .'">'. $topic_title .'</a></td>
</tr>
<tr>
<td><a href="'. $forum_url .'">'. $line[$i]['forum_name'] .'</a>: '. $last_url .' '. $last_time .'<br>-----------------------------------</td>
</tr>';
// ############## output ##############
}
echo '</table>';
mysql_close();
?>
Aber bei der Ausgabe ändert sich (leider) nichts.
Auch möchte ich nicht das sich die Reihenfolge ändert. Also es soll immer vom ersten Posting ausgegangen werden.
Nachricht 4
Nachricht 3
Nachricht 2
Nachricht 1
Wenn eine Neue Nachricht geschreiben wurde. Dann
Nachricht 5
Nachricht 4
Nachricht 3
Nachricht 2
Nachricht 1
Auch wenn zu Nachricht 2 ein Beitrag geschrieben wurde, soll in der Zusammenfassung die Reihenfolge beibehalten werden.
Es wäre toll wenn du da noch eine Antwort für mich hättest!
Sandra
Verfasst: 10.04.2006 18:39
von S2B
Soo, zuerst mal hab ich das Query auf deine Situation angepasst und ein bisschen "ausgemistet":
Code: Alles auswählen
$sql = "SELECT t.*, f.forum_name, p.post_username AS poster_name, p.post_time, pt.post_text, u.username AS poster, u.user_id AS poster_id
FROM {$table_prefix}topics t, {$table_prefix}forums f, {$table_prefix}users u, {$table_prefix}posts p, {$table_prefix}posts_text pt
WHERE $where_forums
AND f.forum_id = t.forum_id
AND p.post_id = t.topic_first_post_id
AND pt.post_id = p.post_id
AND u.user_id = p.poster_id
ORDER BY t.topic_time DESC
LIMIT $topic_limit";
Dann nochmal ausmisten:
Finden:
Code: Alles auswählen
$first_time = date('d.m.Y', $line[$i]['topic_time']);
$first_author = ( $line[$i]['first_poster_id'] != '-1' ) ? '<a href="'. $root_path .'profile.php?mode=viewprofile&u='. $line[$i]['first_poster_id'] .'">'. $line[$i]['first_poster'] .'</a>' : ( ($line[$i]['first_poster_name'] != '' ) ? $line[$i]['first_poster_name'] : 'guest' );
$last_time = date('d.m.Y', $line[$i]['post_time']);
$last_author = ( $line[$i]['last_poster_id'] != '-1' ) ? $line[$i]['last_poster'] : ( ($line[$i]['last_poster_name'] != '' ) ? $line[$i]['last_poster_name'] : 'guest' );
$last_url = '<a href="'. $root_path .'viewtopic.php?p='. $line[$i]['topic_last_post_id'] .'#'. $line[$i]['topic_last_post_id'] .'">'. $last_author .'</a>';
Ersetzen mit:
Code: Alles auswählen
$topic_time = date('d.m.Y', $line[$i]['topic_time']);
$topic_author = ($line[$i]['poster_id'] != -1) ? '<a href="'. $root_path .'profile.php?mode=viewprofile&u='. $line[$i]['poster_id'] .'">'. $line[$i]['poster'] .'</a>' : (($line[$i]['poster_name'] != '') ? $line[$i]['poster_name'] : 'Gast');
Dann musst du nur noch die entsprechenden Variablen in deinem echo ausgeben.

Verfasst: 10.04.2006 18:55
von sandra-muc
Wenn ich es richtig verstanden habe, dann soll ich
Code: Alles auswählen
$sql = "SELECT t.*, f.forum_name, p.post_username AS poster_name, p.post_time, pt.post_text, u.username AS poster, u.user_id AS poster_id
FROM {$table_prefix}topics t, {$table_prefix}forums f, {$table_prefix}users u, {$table_prefix}posts p, {$table_prefix}posts_text pt
WHERE $where_forums
AND f.forum_id = t.forum_id
AND p.post_id = t.topic_first_post_id
AND pt.post_id = p.post_id
AND u.user_id = p.poster_id
ORDER BY t.topic_time DESC
LIMIT $topic_limit";
gegen
Code: Alles auswählen
$sql = "SELECT t.*, f.forum_id, f.forum_name, u.username AS first_poster, u.user_id AS first_poster_id, u2.username AS last_poster, u2.user_id AS last_poster_id, p.post_username AS first_poster_name, p2.post_username AS last_poster_name, p2.post_time, pt.post_text
FROM ". $table_prefix ."topics t, ". $table_prefix ."forums f, ". $table_prefix ."users u, ". $table_prefix ."posts p, ". $table_prefix ."posts p2, ". $table_prefix ."users u2, " . $table_prefix . "posts_text pt
WHERE $where_forums t.topic_poster = u.user_id AND f.forum_id = t.forum_id AND p.post_id = t.topic_first_post_id AND p2.post_id = t.topic_last_post_id AND u2.user_id = p2.poster_id AND pt.post_id = p.post_id
ORDER BY t.topic_last_post_id DESC LIMIT $topic_limit";
ersetzen!
Allerdings bekomme ich dann eine Fehlermeldung:
SQL Statement Error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND f.forum_id = t.forum_id AND p.post_id = t.topic_fir
Verfasst: 10.04.2006 20:42
von S2B
Ähm, nein, den unteren Code (der stand ja schon in deiner Datei) durch den oberen.
Aber im oberen Code scheint ein Fehler zu sein.
Code: Alles auswählen
$sql = "SELECT t.*, f.forum_name, p.post_username AS poster_name, p.post_time, pt.post_text, u.username AS poster, u.user_id AS poster_id
FROM {$table_prefix}topics t, {$table_prefix}forums f, {$table_prefix}users u, {$table_prefix}posts p, {$table_prefix}posts_text pt
WHERE $where_forums
f.forum_id = t.forum_id
AND p.post_id = t.topic_first_post_id
AND pt.post_id = p.post_id
AND u.user_id = p.poster_id
ORDER BY t.topic_time DESC
LIMIT $topic_limit";
Verfasst: 10.04.2006 20:59
von sandra-muc
Super, Perfekt.
Eine kleine Frage habe ich noch zum Schluss.
In welcher Variable steht den die Nachricht.
Ich würde nämlich auch den Nachrichtentext gerne noch unter der jeweiligen Nachrichtenüberschrift einblenden!
Sandra
Verfasst: 10.04.2006 23:24
von S2B
Die Nachricht steht in der Variable
