How can a get a textarea to save line breaks?

I am trying to get my textarea to save the breaks created by a carriage return and display the breaks when the DB field is called. My code is posted below, can someone guide me though my errors?
Thank you,
gorg
$return .= "<div class=\"TBL_dta_holder\"><div class=\"BPT_space\">";
$return .= "<div id=\"ExBT_holder\">Discuss your training:</div>";
$return .= "<div id=\"TB_holder\">";
$tmp = ($result->cb_dltext10) ? nl2br($result->cb_dltext10) : " ";
$return .= "<text id=\"tExplain\">{$tmp}</text>";
$return .= "<textarea id=\"tbExplain\" style=\"display: none;\" rows=\"3\" cols=\"30\"  name=\"{$result->cb_dltext10}\">{$result->cb_dltext10}";
$return .= "</textarea>";
$return .= "<div>&nbsp;</div>";
 

Open in new window

fun_gAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Check out nl2br()
0
Ray PaseurCommented:
You use it when you receive the textarea data in your action script.  You can store the textarea data in your data base with the <br/> tags.

http://us3.php.net/manual/en/function.nl2br.php

HTH, ~Ray
0
Roger BaklundCommented:
Ray, he is allready using nl2br()... :)

gorg,

What kind of object is $result? Is it created like this: $result = mysql_fetch_object(...);

Is the name of the column in the database "cb_dltext10" ?

You should probably not use it as a field name for the textarea: name=\"{$result->cb_dltext10}\"
0
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Ray PaseurCommented:
See if this does it for you.
$return .= "<div class=\"TBL_dta_holder\"><div class=\"BPT_space\">";
$return .= "<div id=\"ExBT_holder\">Discuss your training:</div>";
$return .= "<div id=\"TB_holder\">";
$tmp = $result->cb_dltext10;
$tmp = nl2br($tmp);
$return .= "<text id=\"tExplain\">{$tmp}</text>";
$return .= "<textarea id=\"tbExplain\" style=\"display: none;\" rows=\"3\" cols=\"30\"  name=\"{$result->cb_dltext10}\">$tmp";
$return .= "</textarea>";
$return .= "<div> </div>";
 

Open in new window

0
fun_gAuthor Commented:
Thank you guys for that lickity split answer.

Ray, Your code you supplied is not holding the break and is actually acting the same as mine.

cxr, The field is "cb_dltext10". The "$result" object is from calling an array within a table to call the entries with the same entry date.

0
Ray PaseurCommented:
Are the newline characters present in the data base table?
0
Roger BaklundCommented:
>> The "$result" object is from calling an array within a table to call the entries with the same entry date.

Can you show us this part of your code?
0
fun_gAuthor Commented:
I am not seeing the break in the database. array code is below.

if(count($results) != 0){
	$return .= "\n\t\t</tr>";
}	
 
$entryCount = 0;
$cat = null;
if(count($results)) {
$i = 0;									
$entryCount++;
$result = $results[$i];
$checked 	= JHTML::_('grid.id',   $i, $result->cb_dldate1 );	

Open in new window

0
Ray PaseurCommented:
Surely there is more to the code than that!

Have you used phpMyAdmin to print out the text field from the data base table?  You may be able to find out whether the newline characters are in the data base.  If they are not, then nl2br() can't help you.  In that case I would look to see where the newline characters are getting stripped - probably in the script that updates the data base with information from the textarea.
0
Roger BaklundCommented:
>> I am not seeing the break in the database.

Then the nl2br() function will not create them... maybe they are removed before you save the text in the database?

The nl2br() function converts newline characters (line breaks) into <br> html elements, because newline characters are "not working" in html, they are treated just like space characters. That is why you can write markup like like this in html:

<p>
  This text will be
  displayed on a
  single line.
</p>

To prevent this from beeing displayed on a single line, you can either use <pre> tags, or convert each linefeed into a <br> tag, like the nl2br() function does.

If the text does not contain any linefeeds, then the nl2br() function does nothing. There is however a different function which creates linefeeds or <br> tags: wordwrap().

http://php.net/manual/en/function.wordwrap.php
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
It may be a small point, but nl2br does not actually replace the newline characters.  It inserts HTML line breaks before all newlines in a string.  For most uses the difference does not matter, but if you're looking at strlen() to determine anything about the data, you will see the difference.
0
fun_gAuthor Commented:
Hello Guys,
I apologize for my extremely long vacation from this question. I have been trying to figure out where in the process of updating the SQL entry I am changing the format of the Textarea. I am collecting the information initially with a form using textarea and displaying it as a textbox. When the user edits the text box I have been using ajax code to open the DB entry in a textarea and save with ajax but somewhere in the saving method I have screwed up the textarea formatting. I have been trying to figure this up for way too long. I might have to enter another question to attack this aspect.
gorg
0
Ray PaseurCommented:
I think cxr answered this perfectly. ~Ray
0
Ray PaseurCommented:
CommentID 24488324 seems to cover the issue pretty well.  However I am not sure we got an answer about whether the NewLine characters made it into the data base or were stripped elsewhere.  It seems that the AJAX code described in CommentID 24640863 may be the culprit.

Best to all, ~Ray
0
Roger BaklundCommented:
I also think http:#a24488324 answered the question.

In http:#a24488173 the asker said "I am not seeing the break in the database", which indicates that they are removed before the text is inserted, or when the text is edited. #24488324 explains how breaks work in html context, and also how to create breaks if needed.

In the final comment from the asker AJAX is mentioned, and as Ray suggests, there might be a problem with the AJAX code in this case. Without more info from the asker it is hard to tell. I still think http:#a24488324 answered the original question fairly well.
0
fun_gAuthor Commented:
I have more to do on this but I feel as though you have guided me to the correct issue. I am sorry for my delays in this question.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.