Jump to content

How to Get Linebreaks when Displaying Data from DB


webref.eu

Recommended Posts

Hi All

 

I am displaying data from MySQL, but the linebreaks aren't being recognised.  When I look in MySQL Query Browser there appear to be the linebreak characters there, but when I pull the data from the db and display on a page in the browser, the linebreaks are only whitespace, so the data is displayed continuously without linebreaks. 

 

How do I get the linebreaks to be shown properly on the page?

 

Thanks All

Some snippets from the code: 

 

Getting the data:

 

while ($list = mysql_fetch_assoc($result)) ...

 

Displaying the data:

 

$list['ReviewDesc']

 

I've just found that by using the nl2br function as below I can get linebreaks to be rendered in the browser, so I assume this is the best way of doing it? 

 

nl2br($list['ReviewDesc'])

 

Rgds

 

I've just found that by using the nl2br function as below I can get linebreaks to be rendered in the browser, so I assume this is the best way of doing it? 

 

nl2br($list['ReviewDesc'])

 

Rgds

 

Yes that is the only way. Web browsers ignore whitespace characters. nl2br converts new lines to a HTML line break tag <br />.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.