sinista Posted July 8, 2008 Share Posted July 8, 2008 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 More sharing options...
themistral Posted July 8, 2008 Share Posted July 8, 2008 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! Link to comment https://forums.phpfreaks.com/topic/113717-solved-hi-need-a-little-bit-of-help/#findComment-584367 Share on other sites More sharing options...
pdkv2 Posted July 8, 2008 Share Posted July 8, 2008 Use the function $content = nl2br(string content); this will convert the new line character to the <br/> tags Link to comment https://forums.phpfreaks.com/topic/113717-solved-hi-need-a-little-bit-of-help/#findComment-584377 Share on other sites More sharing options...
sinista Posted July 8, 2008 Author Share Posted July 8, 2008 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:) Link to comment https://forums.phpfreaks.com/topic/113717-solved-hi-need-a-little-bit-of-help/#findComment-584392 Share on other sites More sharing options...
trq Posted July 8, 2008 Share Posted July 8, 2008 Store the content in its raw form, then when you display it call nl2br(). Link to comment https://forums.phpfreaks.com/topic/113717-solved-hi-need-a-little-bit-of-help/#findComment-584395 Share on other sites More sharing options...
sinista Posted July 8, 2008 Author Share Posted July 8, 2008 im a bit of a noob havent been doing this that long, what do you mean by that? Link to comment https://forums.phpfreaks.com/topic/113717-solved-hi-need-a-little-bit-of-help/#findComment-584398 Share on other sites More sharing options...
mbeals Posted July 8, 2008 Share Posted July 8, 2008 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? Link to comment https://forums.phpfreaks.com/topic/113717-solved-hi-need-a-little-bit-of-help/#findComment-584399 Share on other sites More sharing options...
trq Posted July 8, 2008 Share Posted July 8, 2008 Just need to correct that last example of code. <?php $text = mysql_result($result,0,'my_enty'); ?> <div class='my_class'> <?php echo nl2br($text);?> </div> Its really important to get into the habit of using the complete <?php tags. Link to comment https://forums.phpfreaks.com/topic/113717-solved-hi-need-a-little-bit-of-help/#findComment-584402 Share on other sites More sharing options...
sinista Posted July 8, 2008 Author Share Posted July 8, 2008 hey thanks everyone who replied, yeah that did make loads of sence nice 1. cheers guys:) Link to comment https://forums.phpfreaks.com/topic/113717-solved-hi-need-a-little-bit-of-help/#findComment-584403 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.