Author Topic: newlines not showing up when info previously stored in DB is displayed on page  (Read 710 times)

0 Members and 1 Guest are viewing this topic.

Offline newbeeeTopic starter

  • Irregular
  • Posts: 35
    • View Profile
the news field in my database is a text type

what i wish to know is how to have text that has line breaks within the text
still show with these line breaks when i grab the data again to show it in the page it is ment for.

at the moment all the text seems to just continue on one long line and breaks up when the end of the page is reached.

edit file
Code: [Select]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
include("config.php");

if($_POST['submit'] == "submit") {
$update = mysql_query("UPDATE `news` SET `news` = '" . $_POST['news'] . "'");
} else {
$news = mysql_query("SELECT * FROM `news`");
?>
<textarea name="news" cols="80" rows="10"><?=@mysql_result($news, 0, 'news');?></textarea><br>
<input name="submit" type="submit" value="submit">
<?
}
?>
</body>
</html>

display page
Code: [Select]
<?=@mysql_result($mpsurgeries_news, 0, "mpsurgeries_news");?>

Offline Mchl

  • Staff Alumni
  • Freak!
  • *
  • Posts: 8,582
  • Gender: Male
  • That's Largo in my avatar, not me.
    • View Profile
    • FlingBits
Use nl2br() when displaying text.
NetBeans fanatic | ExtJS masochist | C++ denier
PHP4 & MySQL4 are no longer supported.
PHPFreaks Tutorials | PHP Debugging: A Beginner's guide | PHP Security Tutorial || How To Ask Questions The Smart Way
Flingbits tutorials | Class Autoloading

Offline salami1_1

  • Irregular
  • Posts: 18
    • View Profile
and if you don't want the newlines at all use:
$yourstring = str_replace("\n", "", $yourstring);

B.r.