0
嘗試從我的PhpBB安裝中顯示六個最新的帖子。我很滿意它是如何工作的,但它顯示了同一個(最近的)帖子的六個副本,而不是大小獨特的最新帖子。顯示六個最新的PhpBB帖子,而不是六個最新帖子的副本
只是爲了確認,我在論壇上有7個帖子。
<?php
$con = mysqli_connect("localhost", "dbuser", "dbpass", "dbname");
$users = mysqli_query($con, "SELECT * FROM phpbb_user_group WHERE group_id='8'");
while($row = mysqli_fetch_array($users)) {
$developers[] = $row["user_id"];
}
$post = mysqli_query($con, "SELECT * FROM phpbb_posts");
while($row = mysqli_fetch_array($post)) {
$topic_id = $row["topic_id"];
$forum_id = $row["forum_id"];
$post_id = $row["post_id"];
$post_text = $row["post_text"];
$post_time = $row["post_time"];
}
$username = mysqli_query($con, "SELECT * FROM phpbb_users WHERE user_id='2'");
while($row = mysqli_fetch_array($username)) {
$postauthor = $row["username"];
if (strlen($post_text) > 10)
$post_text = wordwrap($post_text, 120);
$post_text = explode("\n", $post_text);
$post_text = $post_text[0] . '...';
$result = mysqli_query($con, "SELECT * FROM phpbb_posts WHERE poster_id='2' LIMIT 6");
while($row = mysqli_fetch_array($result)) {
$content = '<div onclick="location.href=\'http://test.mythros.net/forum/viewtopic.php?f=' . $forum_id . '&p=' . $topic_id . '#p' . $post_id . '\';" class="forum-latest-box">';
$content .= '<div class="forum-latest-userbar">';
$content .= '<div class="forum-latest-avatar">';
$content .= '<img src="https://minotar.net/helm/' . $postauthor . '/40.png">';
$content .= '</div>';
$content .= '<h1>' . $postauthor . '</h1>';
$content .= '</div>';
$content .= '<div class="forum-latest-content">';
$content .= '<div class="forum-latest-text">';
$content .= '"' . $post_text . '"';
$content .= '</div>';
$content .= '<div class="forum-latest-meta">';
$content .= gmdate("F j, Y, g:i a", $post_time);
$content .= '</div>';
$content .= '</div>';
$content .= '</div>';
echo $content;
}
?>
看看你的循環更詳細地說,特別是你要通過帖子打印它們的循環。在那個循環中,你想獲得關於作者的信息,做各種文本轉換,然後打印出結果的文章。 '$ post_text'從哪裏來?你什麼時候設置的?它是否打印出您認爲正在打印的內容? – 2014-09-10 23:27:41
@ialarmedalien $ post_text 來自 $ post_text = $ row [「post_text」]; 從數據庫中拉出phpbb文章的文本。它似乎正在展示我想要的東西,只是所有六個「條目」都顯示了相同的帖子信息。 – Skulburn 2014-09-10 23:31:45
查看$ post_text等正在設置的循環;它正在通過論壇上的所有帖子並將這些變量設置爲適當的值。但是,它僅保存* last * post中的數據,因爲每個循環會覆蓋前一個循環中的數據。你現在明白了這個問題嗎? – 2014-09-10 23:35:44