Friday, February 15, 2013

Paragraph Retrieval from Mysql

Greetings of the Day!!!

When I was working with one of the website Designing, I noticed a strange problem. May be it's not a problem. But for a developer it looks like a problem. Many of us can come across such issue. So I thought of penning down the known solution for it.

When you store some paragraph of the text in a MySql database. The column type may be text or Varchar. After retrieving it with a PHP , I see that, it skips the paragraphs and just shows them ina a plain text. No paragraphs. But all the text together displays as one paragraph. Which looks very odd.

I just tried to change the column types, etc as everybody does. But all were in vein. Then I tried to search in web and I found a solution for that. The solution is very simple and effective. You need to use "nl2br( )" functions with the retrieval to show the data with the paragraph...


When you want to get the job Description with the full paragraphs indentation from the Mysql, you can use nlebr() before fetching the data. Here is the snippet

echo nl2br($row_jobdetails['job_description']);

That's it. It does all the trick. Happy Coding!!!

No comments: