Forum Moderators: coopster

Message Too Old, No Replies

Text without carriage returns Help!

         

Shaman13

6:54 pm on Jun 3, 2005 (gmt 0)

10+ Year Member



I am hoping that someone can help me with the formatting of my output. I am using Php 4.3.4 and MySQL as my database. My problem..... I have a text field for notes. This allows users to type notes into a textarea. Notes display fine with carriage returns in the submission form but in my printout form they are all crowded together.

Example in the submission form
This is Line 1.
This is Line 2.
This is Line 3.

Example in the form used for printing
This is Line 1.This is Line 2.This is Line 3.

How can I get my printed output to look like it does in the submission form. Here is the code I am using to pull the information from the table. If someone could show me how to get the right output I would really be thankful.

<b>Summary&nbsp; </b><br><br> <?php

$result = mysql_fetch_array(mysql_query("SELECT SUMMARY FROM _clientsw_cases WHERE CASENUM = '{$_SESSION['CASENUM']}'"));
$user_val = $result['SUMMARY'];

$query = mysql_query("SELECT * FROM _clientsw_cases");
while($array = mysql_fetch_array($query)) {
if($array['SUMMARY'] == $user_val) {

print "<option value=$array[SUMMARY]>$array[SUMMARY]</option>";
}
}
?>

StupidScript

8:29 pm on Jun 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When you pull the textarea content from the db, run it through
nl2br
:

echo nl2br($array['SUMMARY']);

That'll replace the newlines in the content with HTML linebreaks.

mcibor

9:57 pm on Jun 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think that you need a new line after option:

print "<option value=$array[SUMMARY]>$array[SUMMARY]</option>\n";

Where exactly do you need the carriage return? In text you write? Then use what StupidScript has written. If in source, then use "\n" more.

Best regards
Michal Cibor

dreamcatcher

10:18 pm on Jun 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Its a little confusing. So, you are entering data in a textarea and then displaying the data in a drop down menu?

From the example, looks like an actual line break is needed.

print "<option value=$array[SUMMARY]>$array[SUMMARY]</option><br>";

Or is it getting late and I`m not seeing things correctly?

dc

Shaman13

5:56 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



Thank you all so much. Once again this forum has come to my rescue. I used echo nl2br($array['SUMMARY']); Thanks so much! It worked great! As an afterthought is there a way to insert either an additional carriage return or a line of characters between each entry in the text area field when I pull it from the database to make my ouput more readable.

Thanks for all your replies

mcibor

8:16 pm on Jun 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes. you can do it either while printing the array out:

foreach($array as $value) echo nl2br($value)."\n";

or implode it with "\n":

echo implode("\n", nl2br($array)); //However I don't know if nl2br works on arrays as well.

Best regards
Michal Cibor

Shaman13

8:57 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



Thanks Michal!

I can't wait to try it out. Have a Awesome Day!

Many Thanks

Habtom

11:23 am on Jul 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks guys. . .

this really helped me.

Habtom