dsjoes Posted January 28, 2011 Share Posted January 28, 2011 anyway to get text from an sql database so that it retains it's line breaks so that i don't have to use the break code every time i start a new line. Quote Link to comment https://forums.phpfreaks.com/topic/225913-sql-question/ Share on other sites More sharing options...
Pikachu2000 Posted January 28, 2011 Share Posted January 28, 2011 It does retain them. Post an example of your code that has the problem. Quote Link to comment https://forums.phpfreaks.com/topic/225913-sql-question/#findComment-1166346 Share on other sites More sharing options...
dsjoes Posted January 28, 2011 Author Share Posted January 28, 2011 if i enter hello hello it shows as hello hello on the code below but in mysql database it shows the gap in the first bit this displays it <?php $con = mysql_connect("","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("", $con); $result = mysql_query("SELECT * FROM News"); while($row = mysql_fetch_array($result)) { echo $row['News']; } mysql_close($con); ?> and this submits to the database <?php include("dbinfo.inc.php"); mysql_connect($localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM News WHERE id='$id'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $News=mysql_result($result,$i,"News"); ?> <form action="updated.php"> <input type="hidden" name="ud_id" value="<? echo "$id"; ?>"> News:<br> <TEXTAREA NAME="ud_News" COLS=40 ROWS=6><? echo "$News"?></TEXTAREA><br> <input type="Submit" value="Update"> </form> <?php ++$i; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/225913-sql-question/#findComment-1166484 Share on other sites More sharing options...
trq Posted January 28, 2011 Share Posted January 28, 2011 HTML uses <br> tags to indicate a newline. Hence, you'll need to insert a <br> tag everywhere there is a newline char. There is a builtin function for this: nl2br. This only needs to be used when youi want to display your data, not on the way into the database. Quote Link to comment https://forums.phpfreaks.com/topic/225913-sql-question/#findComment-1166497 Share on other sites More sharing options...
dsjoes Posted January 28, 2011 Author Share Posted January 28, 2011 HTML uses <br> tags to indicate a newline. Hence, you'll need to insert a <br> tag everywhere there is a newline char. There is a builtin function for this: nl2br. This only needs to be used when youi want to display your data, not on the way into the database. thanks that is what i was looking for i didn't want to use <br> all the time Quote Link to comment https://forums.phpfreaks.com/topic/225913-sql-question/#findComment-1166511 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.