2013-02-16 51 views
1

我正在构建一个私人消息系统,而我的数据库有多行。 在数据库:Mysql查询格式问题

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

在此先感谢。

+0

您有
来代替行尾:) – HamZa 2013-02-16 22:50:39

+0

您可以验证换行符正在在HTML源包括(例如点击右键,查看网页源代码)。我认为你的问题是HTML的呈现。每个换行符前面插入的'
'标签可能是您的门票。 – spencer7593 2013-02-16 23:00:25

回答

3

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

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