简体   繁体   English

如何在 html+php+mysql 制作的留言簿的评论框下方放置评论?

[英]How to Place comments right under the comment box in a guestbook made in html+php+mysql?

I have one guestbook application where an user can enter his name, email and message and then it's stored on a database which I open it afterwards through a php file to view the comments.我有一个留言簿应用程序,用户可以在其中输入他的姓名、电子邮件和消息,然后将其存储在数据库中,然后我通过 php 文件打开它以查看评论。

My question is: How can I add those comments (when the user clicks submit buttoN) directly to the html page under the comment box in descending order by post hour/date?我的问题是:如何按发布时间/日期降序将这些评论(当用户单击提交按钮时)直接添加到评论框下的 html 页面? ( i don't need the date/hour to be displayed, I just want the comments to be placed consecutively) (我不需要显示日期/小时,我只想连续放置评论)

I use guestbook.php to take the data from db and display it when a user clicks on it(it's a button on my index.html page named Guestbook).我使用guestbook.php 从db 获取数据并在用户单击它时显示它(它是我的index.html 页面上名为Guestbook 的按钮)。 Here is the code for Guestbook.php:以下是 Guestbook.php 的代码:

<?php
$host="localhost"; //Add your SQL Server host here
$user="db1"; //SQL Username
$pass="test123"; //SQL Password
$dbname="db1"; //SQL Database Name
$con=mysqli_connect($host,$user,$pass,$dbname);
if (mysqli_connect_errno($con))
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT name,message FROM db1");
while($row = mysqli_fetch_array($result))
{ ?>
<h3><?php echo $row['name']; ?></h3>
<p><?php echo $row['message']; ?></p>
<?php } 
    mysqli_close($con);
?>

And I'll show u the part of my index.html code(the body) which contains the name, email, message box, security check box and the footer:我将向您展示我的 index.html 代码(正文)的一部分,其中包含姓名、电子邮件、消息框、安全复选框和页脚:

<ul id="mainMenu">
    <li><a href="index.html">Home</a></li>
    <li><a href="guestbook.php" id="active">Guestbook</a></li>
</ul>
<hr/>
</div>
<div id="content">

<h2>Sign to the Guest Book </h2>
    <form name="guest" method="post" action="addcomment.php" onsubmit="return Validate();">
        <span>Name:</span>    <input type="text" name="name"/><br />
        <span>Email:</span> <input type="text" name="email"/><br />
        <p>Message:</p> <textarea name="message" rows="10" cols="50"> </textarea> <br />
        <p>5+5 = ? (in letters):</p> <input type="text" name="res"> </textarea> <br />
        <input type="submit" value="Sign this in the Book" />
  </form>
</div>
</div>
<div id="footer">
<hr/>
<p>Thank you for the visit! </p>
</div>
</body>
</html>

So, i'm thinking that somehow it's possible to replace the footer with a section which will contain the comments underneath...but idk how to take those comments from db and place them there using html code所以,我想以某种方式可以用包含下面评论的部分替换页脚......但是idk如何从数据库中获取这些评论并使用html代码将它们放在那里

Thanks in advance!提前致谢!

Use the .prepend() function:使用.prepend()函数:

var information = ""; // The information from the form.
$("#footer").prepend(information);

If I get you right, what you want to do is:如果我猜对了,你想做的是:

  1. Rename your index.html to index.php将您的index.html重命名为index.php
  2. Add <?php include ("guestbook.php"); ?>添加<?php include ("guestbook.php"); ?> <?php include ("guestbook.php"); ?> to the file where you want the entries to appear. <?php include ("guestbook.php"); ?>到您希望条目出现的文件。

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

相关问题 如何制作评论框,最好使用 javascript 或 php,然后显示评论? - How do I make a comment box, using preferablely javascript or php, and then show the comments? 如何在多个显示的评论上显示/隐藏回复评论框 - how to show/hide reply comment box on multiple displayed comments 如何限制在disqus评论框中显示评论 - how can i limit showing comments in disqus comment box 如何以特定的HTML格式放置php制成的下拉列表? - How can I place a drop-down list made in php in a specific HTML form? 如何将div克隆放置在原始div下? - How to place div clone right under original div? 如何将 Javascript 放入 SVG html 盒子中 - How to place Javascript in SVG html box 当用户在此有效的javascript注释框中提交评论时,您将如何添加用户图像和名称 - how would you add a user image and a name when a user submits a comment in this working javascript comments box 如何用 AJAX 告诉 PHP 在文章下显示哪些评论? - How to tell PHP which comments to show under the article with AJAX? Facebook 社交插件:如何为 Facebook 评论框中的“查看更多”评论添加事件处理程序? - Facebook Social Plugin: How do I add an event handler for “View More” comments on the Facebook comment box? JavaScript-如何在文本框的右侧放置星号? - JavaScript - How to place asterisk in the right side of the text box?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM