我網站上的論壇頁面使用PHP創建表格,然後使用while循環從數據庫中填充它。這工作正常,並始終有,但我試圖將錨點,'鏈接',標籤從帖子標題左右移動到表格中帖子的整個第一部分。要做到這一點,經過以下步驟:PHP while循環呼應元素以外的循環內容
- 打開表標籤[循環外]
- 回聲報頭[循環外]
- 開始WHILE循環,使得對於每一個崗位另一篇文章部分找到。
- 創建錶行
- 創建表數據
- 回聲內容
- 關閉表數據
- 重複步驟5-7再次進行後日期部分
- 關閉錶行
- 關閉表[OUSTIDE OF LOOP]
它應該使鏈接在所有的第一部分點擊, d爲表這樣中:
<table> <--- *THIS IS BEFORE THE LOOP, IT GETS RUN ONCE ONLY* -->
<WHILE *do this like 5 times or something*>
<tr>
<a *category link*>
<td>
*content for the 'td' which is taken from the DB*
</td>
<td>
*content for the 'td' which is taken from the DB*
</td>
</a>
</tr>
<ENDWHILE>
</table>
然而,在實踐中,他們最終在表格之外可在該截圖中可以看出:
任何人都可以請解釋這以及如何解決它?
echo '<table class="forumTable">
<tr>
<th>Category</th>
<th>Last topic</th>
</tr>';
while($row = mysqli_fetch_assoc($catResult)){
echo '<tr>';
echo '<a href="category.php?id=' . htmlspecialchars($row['catID']) . '"><td class="catDesc">';
echo '<h3>' . $row['catName'] . '</h3>' . $row['catDesc'];
echo '</td>';
echo '<td class="catTime">';
$getTops = "SELECT topicID, topicSubject, topicDate, topicCat FROM topics WHERE topicCat = " . $row['catID'] . " ORDER BY topicDate DESC LIMIT 1";
$topResult = mysqli_query($connect, $getTops);
if(!$topResult){
echo '<p style="margin-top: 75px;">The last topic could not be displayed, please try again later.</p>';
}
else{
if(mysqli_num_rows($topResult) == 0){
echo '<p>No topics</p>';
}
else{
while($topRow = mysqli_fetch_assoc($topResult)){
echo '<a href="topic.php?id=' . $topRow['topicID'] . '">' . $topRow['topicSubject'] . '</a> at ' . $topRow['topicDate'];
}
}
}
echo '</td></a>';
echo '</tr>';
}
echo '</table>';
您需要顯示實際的代碼,而不是''。 –
AbraCadaver
顯示一些代碼,以便我們能夠回答您的問題。 –
ahh對不起,我忘了這麼做。編輯帖子。 – iixCarbonxZz