简体   繁体   English

如何在线显示评论

[英]How to display comments inline

So I have this code (which works) that prints out the comments a user has just written. 因此,我有这段代码(有效)可以打印出用户刚刚编写的注释。 The issue im having is with displaying the comments. 我的问题是显示评论。 The username is displayed above the comment and I just want them to be displayed next to each other for example 用户名显示在评论上方,例如,我只希望它们彼此相邻显示。

'Username:'comment'' '用户名:'评论'

I have tried putting display:inline; 我试过把display:inline; in my CSS for h4 and p but it messes up everything else that i have put into these elements. 在我的CSS中,用于h4和p,但它弄乱了我在这些元素中添加的所有其他内容。

Does anyone know the answer? 有人知道答案吗?

This is my code 这是我的代码

 //Print out existing comment
    $query = "SELECT * FROM comments JOIN users ON comments.userID = users.ID WHERE salonID=$salonid"; 
    $result = mysqli_query($db_server, $query);
    if (!$result) die("Database access failed: " . mysqli_error($db_server));
    while ($row = mysqli_fetch_array($result)){
            $str_comments .= "<div id='comments'><h4>" . $row['Username'] ."</h4><p>'" . $row['comment'] . "'</p>";
            $str_comments .="<img src='" . $row['imagename'] ."' /></div>";
    }

You put username inside <h4></h4> which is a block element. 您将用户名放在<h4></h4> ,这是一个块元素。 It's the same for <p></p> . <p></p>

Block element will take a full row so you won't be able to place username & comment in a line. 块元素将占据整行,因此您将不能在行中放置用户名和注释。

You already give display:inline style for <h4></h4> & <p></p> it should be fine. 您已经为<h4></h4><p></p>提供了display:inline样式,应该没问题。

I encourage you to use a <span></span> instead which is an inline element by default. 我鼓励您使用<span></span>代替,默认情况下它是一个内联元素。

Focus on this: 专注于此:

while ($row = mysqli_fetch_array($result)){
  $str_comments .= "<div id='comments'>" . 
                   "<span style='font-weigth:bold;'>" . $row['Username'] ."</span>" .
                   "<span>'" . $row['comment'] . "'</span>" . 
                   "<img src='" . $row['imagename'] ."' />".
                   "</div>";
}

The easiest way to do it on your website is use annote ( http://annote.in ). 在您的网站上最简单的方法是使用annote( http://annote.in )。 A javascript based inline comment plugin. 一个基于javascript的嵌入式注释插件。 You can get started on any platform in minutes. 您可以在几分钟内在任何平台上入门。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM