最后一行仍显示<div> </div>

时间:2014-02-26 02:44:58

标签: php css

我正在学习PHP / MySQLi,我需要帮助一些我似乎无法在网上找到的东西。我在我正在制作的论坛脚本中的每个主题之后使用<div class="hr"> </div>但是我不希望它在最后一个主题之后显示它们,如何阻止我的脚本在最后一行之后显示它?我会感激任何帮助,所以我100%明确。

        Here is how it looks:

         Topic Title Here
        -------------------------------------
        Topic Title Here
        -------------------------------------

        But I want:

         Topic Title Here
        -------------------------------------
        Topic Title Here

        My code of where this part is:

             <?php
    }
          $dn2 = mysql_query('select t.id, t.title, t.authorid, u.username
         as author,
      count(r.id) as replies from topics as t left join topics as r on     
        r.parent="'.$id.'"
      and r.id=t.id and r.id2!=1  left join users as u on u.id=t.authorid
      where t.parent="'.$id.'" and t.id2=1 group by t.id order by t.timestamp2 desc');

    if(mysql_num_rows($dn2)>0)
    {
    ?>

    <table id="main-table">
    <tr>
        <td id="side">
                      </td>

        <td id="content">
    <?php
    while($dnn2 = mysql_fetch_array($dn2))
    {
    ?>

        <div><a href="read_topic.php?id=<?php echo $dnn2['id']; ?>">
          <?php echo htmlentities($dnn2['title'], ENT_QUOTES, 'UTF-8'); ?></a>
        - <a class="wtb" href="profile.php?id=<?php echo $dnn2['authorid']; ?>">
           <?php echo htmlentities($dnn2['author'], ENT_QUOTES, 'UTF-8'); ?></a></div>

        <div class="hr"> </div>

<?php
}
?>

2 个答案:

答案 0 :(得分:1)

在没有看到你的代码的情况下,一个简单的方法就是先画线,除非它是第一个主题

    if ($topicNumber != 1) echo ('<div class="hr"> </div>');
    <div><?php echo $dnn1['topic']; ?><div>
    <? } ?>

答案 1 :(得分:0)

您可以使用css轻松处理此问题:

<style>
.wrapper div {border-bottom: 1px dashed black}
.wrapper div:last-child{ border-bottom: 0}
</style>

<div class="wrapper">   

    <div><?php echo $dnn1['topic']; ?><div>
    <? } ?>     

</div>