查看第二个回应下的第二个回声
do {
echo "<strong>Topic:". $row_AllTopics['topic'] . "</strong><br>";
mysql_select_db($database_Select, $Select);
$query_Comments = sprintf("SELECT * FROM comments where ((event_id=%s) AND (topic_id=%s)) ", $_POST['event_id'], $row_AllTopics['id']);
$Comments = mysql_query($query_Comments, $Select) or die(mysql_error());
$row_Comments = mysql_fetch_assoc($Comments);
$totalRows_Comments = mysql_num_rows($Comments);
do {
// This is the echo in question.
echo $row_Comments['comment'] . "Posted by: ". $row_Comments['poster'] . "\n";
} while ($row_Comments = mysql_fetch_assoc($Comments));
} while ($row_AllTopics = mysql_fetch_assoc($AllTopics));
(此文字全部居中对齐在屏幕上)
Topic:computer
linuxPosted by: andy linuxPosted by: andy Topic:computer
Posted by: Topic:ji
poPosted by: andy Topic:drive
makPosted by: andy Topic:new
nicePosted by: andy Topic:golf
holePosted by: andy plPosted by: andy
答案 0 :(得分:1)
而不是\n
,请尝试使用<br>
。
答案 1 :(得分:0)
您可以在PHP中使用nl2br()函数:
echo nl2br($row_Comments['comment'] . "Posted by: ". $row_Comments['poster'] . "\n");
这会将\n
转换为<br/>
。
答案 2 :(得分:0)
"\n"
将导致源代码中的换行符。虽然您的浏览器将呈现html,但您需要使用HTML换行符(<br>
或<br />
),这将给出预期的结果。
所以,你的代码将是这样的:
之前: echo $row_Comments['comment'] . "Posted by: ". $row_Comments['poster'] . "\n";
之后: echo $row_Comments['comment'] . "Posted by: ". $row_Comments['poster'] . "<br />";