Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying multiple lines from field

Status
Not open for further replies.

markhkram

IS-IT--Management
Dec 30, 2008
32
0
0
US
I have a basic MySql database, and am trying to display a field with multiple lines entered. Only 1 line displays.

For example, the following text entered:
Line 1
Line 2

Will display the following when retrieved:
Line 1 Line 2

However in PHP My Admin when displaying the record, it displays it as:
Line 1
Line 2

How can I make this field display the lines correctly?

Thanks

Code:
<?
//My Code
$Comment=mysql_result($result,$i,"Comment");

echo $Comment; 
?>
 
Figured it out, had to use the following:

Code:
echo str_replace("\n", "<br>", $Comment);
 
or use the optimised built in function nl2br()
 
Or surround the output with <pre> tags as it appears to be pre-formatted text.

echo "<pre>$Comment</pre>";



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top