Solved

How can I place a carriage return in text field from database?

Posted on 2009-05-02
7
335 Views
Last Modified: 2014-11-12
I have setup a multi-line text field for entry to a database. Many users try separating items and tesk by hitting enter supplying them with a new line within the text field although when the data is queried and displayed in the page it does not show the carriage return that has been used for oganization.

I have seen this on Google calendar and I am trying to get that look. How is this done?

Thank you all,
gorg
0
Comment
Question by:fun_g
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24288487
Use the nl2br() function:

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

This function converts linefeeds to <br> tags, so that they break lines in html.
0
 

Author Comment

by:fun_g
ID: 24288521
cxr,
Thank you very much for your quick response.
This function looks like it is more geared for line by line query from the database. I am submitting a text field and calling the text field to display the data on the page. Within the text field I need to preserve the carriage returns for display within the text box on the page.

Thank you,
gorg
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24289426
Can you show your code?

>> for display within the text box

What kind of text box? A <textarea>? Or a paragraph <p> or <div>?

For a textarea, no conversion should be necessary. For a paragraph or div, use nl2br().
0
Webinar: Security & Encryption in the MySQL world

Join Percona’s Solutions Engineer, Dimitri Vanoverbeke as he presents “Security and Encryption in the MySQL world” on Thursday, July 6, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

 

Author Comment

by:fun_g
ID: 24289967
The entry in the form is a <textarea> but the code that I am calling it back with is listed below. How can I call it to a <textarea>. Lack of knowledge here. :(



$return .= "<td>";
														$tmp = ($dietsheet->text_5) ? $dietsheet->text_5 : "&nbsp";
$return .= "<div id=\"tDSText5_$dietsheet->cf_id\">{$tmp}</div>";
$return .= "<input id=\"tbDSText5_$dietsheet->cf_id\" style=\"display: none; float: left; width: 70%\" type=\"text\" value=\"{$dietsheet->text_5}\">";
$return .= "</td>";

Open in new window

0
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 500 total points
ID: 24290669
Have you tried nl2br()? Try the code below.

>> How can I call it to a <textarea>

"call it"... do you mean display it in a textarea? Just wrap it in a textarea tags:

$return .= "<div id=\"tDSText5_$dietsheet->cf_id\"><textarea>{$tmp}</textarea></div>";

If you use a textarea, you should NOT use nl2br().

PS: I added a semicolon to your &nbsp; In many cases the browser will understand it without the ; but it is correct to end it with a ; character.
$tmp = ($dietsheet->text_5) ? nl2br($dietsheet->text_5) : "&nbsp;";

Open in new window

0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24290676
Heh! I forgot, EE removes the &nbsp; from the code snippet. The " " at the end of the code snippet contained &nbsp; (nonbreakable space)
0
 

Author Comment

by:fun_g
ID: 24292210
cxr,
The addition 'n12br' worked perfect. Thank you very much. This has loaded the page with the correct format. Thank you for your time.
gorg
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
By using UNIQUE function in Google Sheets, you can get around removing duplicates like in Microsoft Excel.
This Micro Tutorial demonstrates how to quickly find related content for YourTango's posts using MozBar Chrome extension.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question