0

我正在显示从数据库中检索到的数据的一部分(作者和日期)。但我希望实现一种“阅读更多”,其中作者超链接到完整结果,即当我点击作者和日期时,评论会附加到它上面。我会欣赏一个例子。谢谢

    <body>
    <?php
    session_start();
    $u = $_SESSION['username'];
    if(isset ($_SESSION['username']))
      {
        $database = "xxxx";
        $Username = "username";
        $Password = "password";

        $con="host=localhost port=5432 dbname=$database user=$Username password=$Password";
        $db=pg_connect($con) or die('connection failed');
        $query = 'select a.name,p.date,p.comment from author a, post p where a.name = p.author';
        $posts = pg_query($db, $query);                   
      }
    ?>

    <div class = "result">
    <h2>Show Result</h2>
    <?php
     while($row=pg_fetch_assoc($posts))
     {
       $author=$row['a.name'];
       $date=$row['p.date'];
       echo "<p><a href='#'>$author:$date</a></p>";
     }
     ?>
    </div>
    </body>
4

1 回答 1

1

在 HTML 中添加注释:

   $author=$row['a.name'];
   $date=$row['p.date'];
   $comment=$row['p.comment'];
   echo "<p><a href='#'>$author:$date</a><span class=\"comment\">$comment</span></p>";

并添加此代码 JS :

$(function(){
    $(".result p > span.comment").hide(0);
    $(".result p > a").click(function(e){
        var comment = $(this).parent().find("span.comment");
        if (comment.is(":visible"))
            comment.slideUp();
        else
            comment.slideDown();
        return false;
    });
});

(你已经添加了标签 jQuery,所以我认为你使用它)

于 2013-11-03T14:16:25.880 回答