gpt4 book ai didi

php - 如何在每个 MySQL 字段结果之间放置标记?

转载 作者:行者123 更新时间:2023-11-29 14:07:59 26 4
gpt4 key购买 nike

我正在用 PHP 为我的网站制作一个评论框。这是代码:

$con = mysql_connect($hostname,$username,$password); // Connect to MySQL database
if (!$con)
{
die("Could not connect: " . mysql_error());
}
mysql_select_db($dbname);
if(isset($_POST["submit"]))
{
$comment=$_POST["comment"];
$q="INSERT INTO comments_table (comments) VALUES ('$comment')"; // Could also be (\"comment\")
mysql_query($q);
}
$q="SELECT comments FROM comments_table";
$result=mysql_query($q);
while($row=mysql_fetch_array($result))
{
// List the comments - how could I get some markup between each to make each have it's own area?
echo $row['comments']."";
}
?>
<html>
<body>
<form method="post" action="/comments-test.php">
<textarea name="comment" rows=30 cols=10></textarea>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

我想知道的是我应该如何让每个评论都有自己的框或标记。每个评论之间不能是相同的 HTML(例如 ,</div><div class="comment"> ),否则评论末尾会出现一些没有结束标记的评论框,并且开头会有一个杂散的结束标记。我是 SQL 新手,但不是 PHP 新手。我该怎么做?

最佳答案

  // List the comments - how could I get some markup between each to make each have it's own area?
echo '<div class="comment">'.$row['comments']."</div>";

这行得通吗?

关于php - 如何在每个 MySQL 字段结果之间放置标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14046570/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com