1

我正在构建一个私人消息系统,我的数据库有多行。在数据库中:

I love that song do you?

-Joe

但我的查询最终显示如下

I love that song do you? -Joe

这是我的查询

<?php
include 'core/init.php';
protect_page();
include 'includes/overall/header.php';
$username = $user_data['username'];
?>
<?php
$result = mysql_query("SELECT * FROM messages Where sentto1='$username'");
echo '<h2>Messages: </h2><br>';
while($row = mysql_fetch_array($result)){


  echo '<b>From: ';
  echo $row['from1'];
  echo '</b><br><br>';

  echo 'Subject: ';
  echo $row['subject1'];

  echo '<br><br>';
  echo 'Message: ';
  echo $row['message1'];
  echo "<br />";
echo "<br />";
  }

?>
<?php include 'includes/overall/footer.php'; ?>

提前致谢。

4

1 回答 1

3

使用nl2br()<br> ,它将用 HTML标记替换所有换行符。

  echo nl2br($row['message1'], false);
于 2013-02-16T22:54:04.927 回答