Solved

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

Posted on 2009-05-02
7
332 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
  • 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
This Micro Tutorial will demonstrate without sampling how to find out top organic landing pages. The hack gets around the standard way to find the pages in Google Analytics results in sampling for larger sites.
This Micro Tutorial will demonstrate the easy use of Gmail embedding images in your email so the recipient of your email can view them in context.

770 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