Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 8th, 2004, 08:12 AM
Authorized User
Join Date: Jul 2004
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rajuru Send a message via Yahoo to rajuru
Default problem retrieving from database

I have put a form in my page which results saves to database.
In my form there is a TextArea field.
I am inserting and retriveing data from mysql database. No problem

But problem is that when I retrieve data from database I don't see the line breaks that I have given in the field.
For Example:
I typed the following text in the TextArea field

"A quick brown
fox jumps over
the lazy dog"

But I retrieve data I see "A quick brown fox jumpbs over the lazy dog" all in a line. There is no line break

What should I do now?

Best Regard:
Md. Zakir Hossain (Raju)

www.rajuru.xenexbd.com - my blog with PHP scripts, PHP Book Review and many more
Old October 8th, 2004, 12:23 PM
Friend of Wrox
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts

When you echo the data from the database do this:

$from_the_database = nl2br($from_the_database);

echo $from_the_database;


-Snib <><
There are only two stupid questions: the one you don't ask, and the one you ask more than once ;)
Old October 8th, 2004, 12:34 PM
richard.york's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts

BTW: This happens because HTML does not interpret line breaks. The nl2br (new line to break) function inserts XHTML line breaks (<br/>) where ever newline characters (\n) occur in the string.

Besides server-side technologies like PHP, there are a few client-side options as well.

echo "<pre>\n".

Then add a stylesheet rule for browsers that don't support the <pre> element, though I can't remember ATM which browsers don't support it.

pre {
    display: block;
    white-space: pre;

The preceding CSS rule preserves both the whitespace and the line breaks.



[http://pear.php.net/Mail_IMAP] A PHP/C-Client/PEAR solution for webmail

Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieving and uploading image in Database vijay_83 ASP.NET 2.0 Basics 1 October 4th, 2006 03:25 PM
retrieving single value from database Moharo PHP How-To 2 July 5th, 2005 03:29 AM
retrieving from database... URGENT!!! roryosullivan JSP Basics 1 March 9th, 2005 03:11 PM
NEED HELP! retrieving from database nvillare .NET Web Services 5 October 22nd, 2004 12:37 AM
NEED HELP! retrieving from database nvillare ADO.NET 1 December 2nd, 2003 10:31 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.