我正在尝试为我的论坛进行分页。我试图从数据库中显示结果,尽管一切都无处不在。
这是我的代码:
<!-- start with the table -->
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="53%" align="center" bgcolor="#E6E6E6" style="padding:5px;"><strong>Topic / Thread Starter</strong></td>
<td width="15%" align="center" bgcolor="#E6E6E6" style="padding:5px;"><strong>Replies/Views</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6" style="padding:5px;"><strong>Last Post By</strong></td>
</tr>
<div id="p1" class="pagedemo _current" style="">
<?php
$sql="SELECT * FROM forum ORDER BY datetime DESC";
$result=mysql_query($sql);
$i = 1;
$z = 1;
while($rows = mysql_fetch_array($result)){ // Start looping table row
if(($i % 4) != 0)
{ ?>
<tr>
<td bgcolor="#FFFFFF" style="padding:5px;"><a class="normal" href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><br /><span style="color:#666; font-size:12px;">Started By <?php echo "<a class='normal' href='http://www.example.com/view_profile.php?user=".getID($rows[username])."'>"; ?> <? echo $rows['username']; ?></a></span></td>
<td align="center" bgcolor="#FFFFFF">Replies: <? echo $rows['reply']; ?><br />Views: <? echo $rows['view']; ?></td>
<td align="center" background="http://example.com/images/forum_fade_bckg.png"><span style="color:#666; font-size:12px;">
<?php echo "<a class='normal' href='http://www.example.com/view_profile.php?user=".getID($rows[lastPoster])."'>"; ?> <?php echo $rows['lastPoster']; ?></a><br /><?php $date = substr($rows['datetime'],0,12);
if($date == date("M d, Y")) {
echo "Today, " . substr($rows['datetime'],-8);
} else {
echo $rows['datetime'];
}?> </span></td>
</tr>
<?php
// do whatever for the page... (this is inside the div)
$message = $row['message'];
echo $i . " " . $message. "<br>";
$i+=1;
}
else
{
$z+=1;
// GET ONLY NUMBERS HERE THAT ARE DIVISIBLE BY 4!!!!
// this is the end of the starting page, and the begining of the next page
echo '<br>---end---</div>
<div id="p'.$z.'" class="pagedemo" style="display:none;">---start---<br>NEXT PAGE!!!!!!!'; //
}
}
?>
</div>
结果,不是停留在 div 中,而是实际上在 div 之下。<tr>
当我用and取出所有东西时</tr>
,它们都适合 div。我究竟做错了什么?