Mysql查询格式问题


Mysql Query formatting issue

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

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'; ?>

提前谢谢。

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

  echo nl2br($row['message1'], false);