sasori Posted October 10, 2008 Share Posted October 10, 2008 i have this problem when outputing the content of my page, here's the screenshot my database contents is this i tried to put "\n" inside the database..and yet nothing happened..it just worsen the output and it output the \n as is Quote Link to comment https://forums.phpfreaks.com/topic/127823-solved-mysql-newline-help/ Share on other sites More sharing options...
JasonLewis Posted October 10, 2008 Share Posted October 10, 2008 Check out nl2br(). You need to convert the new line characters to HTML line breaks. Quote Link to comment https://forums.phpfreaks.com/topic/127823-solved-mysql-newline-help/#findComment-661749 Share on other sites More sharing options...
sasori Posted October 10, 2008 Author Share Posted October 10, 2008 but sir, the problem is with the data that i input in the database.. its a 3 liner..but when pull it out and output it using PHP,, it produces a single line only Quote Link to comment https://forums.phpfreaks.com/topic/127823-solved-mysql-newline-help/#findComment-661754 Share on other sites More sharing options...
eddy556 Posted October 10, 2008 Share Posted October 10, 2008 Why don't you store in the database with <br /> after each line. This should then format it correctly on the page. Quote Link to comment https://forums.phpfreaks.com/topic/127823-solved-mysql-newline-help/#findComment-661874 Share on other sites More sharing options...
eddy556 Posted October 10, 2008 Share Posted October 10, 2008 In addition it looks like you're using your database wrong, surely line should be a different record? Each tied together with the foreign key (i.e. yours) Quote Link to comment https://forums.phpfreaks.com/topic/127823-solved-mysql-newline-help/#findComment-661876 Share on other sites More sharing options...
sasori Posted October 10, 2008 Author Share Posted October 10, 2008 it worked with the <br/> tag..i never thought that is possible. thank sir Quote Link to comment https://forums.phpfreaks.com/topic/127823-solved-mysql-newline-help/#findComment-661882 Share on other sites More sharing options...
eddy556 Posted October 10, 2008 Share Posted October 10, 2008 no problem, the first topic I've solved :D :D Quote Link to comment https://forums.phpfreaks.com/topic/127823-solved-mysql-newline-help/#findComment-661960 Share on other sites More sharing options...
JasonLewis Posted October 11, 2008 Share Posted October 11, 2008 No, no, no! If it's stored in the database as 3 lines, like so: Hey this is three lines! Then all you need to do is grab the data from the database and use nl2br() on it. You shouldn't be inserting HTML tags into the database when what it's doing is perfectly normally. So you get your data: $connect = mysql_connect("localhost", "root", ""); mysql_select_db("database"); $query = mysql_query("SELECT textarea FROM table WHERE id='1'") or die(mysql_error()); //just an example query. $data = mysql_fetch_assoc($query); //Fetch the data echo $data['textarea']; //This will display it all on one line, which is wrong. echo "<br /><br />"; echo nl2br($data['textarea']); //After performing the nl2br() function on it it'll convert all \n characters to the HTML equivalent <br /> Make sense? Quote Link to comment https://forums.phpfreaks.com/topic/127823-solved-mysql-newline-help/#findComment-662380 Share on other sites More sharing options...
fenway Posted October 11, 2008 Share Posted October 11, 2008 Yes... please DO NOT store <BR> in the DB. Quote Link to comment https://forums.phpfreaks.com/topic/127823-solved-mysql-newline-help/#findComment-662890 Share on other sites More sharing options...
eddy556 Posted October 11, 2008 Share Posted October 11, 2008 Okay I agree about not storing <br /> in the database as its actually NOTHING to do with the data being stored, however I'm pretty sure if this is true the whole problem here is attempting to store FORMATTING in the database which is also wrong - if these values are fundamentally seperate (they are all different qualifications) they should be stored within different records. I am correct? Quote Link to comment https://forums.phpfreaks.com/topic/127823-solved-mysql-newline-help/#findComment-662918 Share on other sites More sharing options...
sasori Posted October 12, 2008 Author Share Posted October 12, 2008 Check out nl2br(). You need to convert the new line characters to HTML line breaks. thank you very much for the tips. Quote Link to comment https://forums.phpfreaks.com/topic/127823-solved-mysql-newline-help/#findComment-663091 Share on other sites More sharing options...
JasonLewis Posted October 12, 2008 Share Posted October 12, 2008 No worries, just whatever you do... Don't insert HTML into the database. Good luck with your coding. Oh, one more thing. When inserting data, look into functions like mysql_real_escape_string(). Quote Link to comment https://forums.phpfreaks.com/topic/127823-solved-mysql-newline-help/#findComment-663093 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.