【问题标题】:pagination content分页内容
【发布时间】:2012-04-17 16:41:41
【问题描述】:

我正在尝试为我的论坛进行分页。我试图从数据库中显示结果,尽管一切都无处不在。

这是我的代码:

<!-- 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 之下。当我取出 &lt;tr&gt;&lt;/tr&gt; 的所有内容时,它们都适合 div。我做错了什么?

【问题讨论】:

    标签: pagination


    【解决方案1】:

    如果您查看页面的来源,问题应该很明显。我看到一些可能是问题的错误。

    sn-p 顶部的 TABLE 结束 TR 标签,然后一个 DIV 开始。 DIV 应仅位于 TD、TH 或 TABLE 之外。同样在您提供的 sn-p 中,没有结束表标签。所有其他问题都可能是导致浏览器混乱的问题。

    请将结构调整为与此类似:

    <div>...</div>
    <table>
       <tr>
          <td>Some tags in here(A, DIV, SPAN, etc.)</td>
       </tr>
       <tr>
          <td>...</td>
          <td>...</td>
       </tr>
    </table>
    <div>...</div>
    

    另外,将某些属性迁移到样式标签中的 css 属性也是值得的。例如你的 sn-p 中的 background、bgcolor、align 和 width 属性。

    抱歉,如果这不能解决问题,如果无法看到问题,则很难调试。

    【讨论】:

    • 所以 tr 标签应该在那里结束,因为那是第一行。它应该是静态的,因为它下面的内容总是与上面的标题相关联。此外,
      基本上从第一个分页页面开始。这就是它存在的原因。表格在 div 标签中,因为 div 标签是分页页面,并且表格包含在每个页面上找到的数据。
    • 所以我想我目前的主要问题是当假设有更多内容时没有显示下一页。这很奇怪,因为我结束了当前的 div(p1),然后用“---start---
      NEXT PAGE!!!!!!!”打开了新的 div这会显示,但不会显示表中的任何内容(回复、视图等)
    猜你喜欢
    相关资源
    最近更新 更多
    热门标签