我正在为我的网站制作一个 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 新手。我该怎么做?