Jump to content

[SOLVED] hi need a little bit of help


sinista

Recommended Posts

hey ,

 

i  started making a forum the other day and i was wondering, how i get the topics to be displayed as they are written?

 

i.e. someone writes there message

 

blablah blah

blah blah

something

thid id the message

 

but when it gets put in Mysql its written as

 

blablah blah blah blah somethingthid id the message,

 

So what i want to know is how do get the new lines put in so when someone views the message it comes out as it was written

 

blablah blah

blah blah

something

thid id the message

 

Thanks for any help in advance, :)

Link to comment
https://forums.phpfreaks.com/topic/113717-solved-hi-need-a-little-bit-of-help/
Share on other sites

Is it because the formatting is not being held in the database?

So the text that is being imputted loses line breaks...?

 

Or is is that each line comes from a different field so you could just add the line break in your code.

 

Post your code so we can more easily see the problem!  :)

doh i should have thought of bring ing the code out with me,

im in an internet cafe.

 

the code is prob something like

 

ive have a text area box that sends the info to a php page

 

<?php 
include ('db_connect.php');

$text_area=$_POST['text_area'];

$SQl = INSERT INTO `table` (text_area) VALUES ($text_area);
$result = mysql_query($sql);

include ('db_close.php');
?>

 

i think the code is something like what is above,

 

so i guess how do i write it so all the line brakes are taken to the next page and inserted into the database.

 

also just read the last reply where would i put $content = nl2br(string content); into the code,

would it be something like

 


<?php 
include ('db_connect.php');

$text_area=$_POST['text_area'];
$content= nl2br($text_area);

$SQl = INSERT INTO `table` (text_area) VALUES ($content);
$result = mysql_query($sql);

include ('db_close.php');
?>

 

 

again thanks for all the help:)

the line breaks are put into the database.  That's not the issue.

 

What happens is that HTML does parse line breaks (otherwise source formatting would be a pain).  What you have to do is convert the line breaks into <br /> tags when you go to display the text.

 

So insert the data like you have been, but on the page that you plan on displaying the text, just use nl2br().

 

ie:

 

<?
$text = mysql_result($result,0,'my_enty');

?>

<div class='my_class'>
   <?=nl2br($text)?>
</div>

 

 

Make sense?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.