我网站上的论坛页面使用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