|
Subject:
|
problem retrieving from database
|
|
Posted By:
|
rajuru
|
Post Date:
|
10/8/2004 8:12:29 AM
|
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?
|
|
Reply By:
|
Snib
|
Reply Date:
|
10/8/2004 12:23:43 PM
|
When you echo the data from the database do this:
$from_the_database = nl2br($from_the_database);
echo $from_the_database;
HTH!
-Snib <>< http://www.snibworks.com There are only two stupid questions: the one you don't ask, and the one you ask more than once ;-)
|
|
Reply By:
|
richard.york
|
Reply Date:
|
10/8/2004 12:34:59 PM
|
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". $variable. "</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.
HTH!
Regards, Rich
-- [http://www.smilingsouls.net] [http://pear.php.net/Mail_IMAP] A PHP/C-Client/PEAR solution for webmail
|