Page 1 of 1

New line

Posted: Thu Dec 12, 2002 9:10 pm
by sclozza
I am making (attempting!) a database to store news entries, when I run a query to retrieve everything (select * from etc..) it leaves a blank space where the line should be.

Does anyone know how to make it keep the line when formatting?

The data type is 'blob' if that helps

Thanks.

Posted: Thu Dec 12, 2002 9:14 pm
by aybra
? what is the actual code your using?

Posted: Thu Dec 12, 2002 9:25 pm
by sclozza
Whoops, sorry. :oops:

Code: Select all

<?
 
  $time = $_POST&#1111;"time"];
  $subject = $_POST&#1111;"subject"];
  $news = $_POST&#1111;"news"];

  $dbcnx = @mysql_connect("localhost", "user", "pass") . 
  mysql_select_db("blog");

  $add = "INSERT INTO news (time, subject, content) VALUES ('$time', '$subject', '$news')";

  $added = mysql_query($add); 

  $test = mysql_connect("localhost", "root", "") or die ("Something's wrong");
  mysql_select_db("blog") or die ("Something is wrong");
  $result = mysql_query("SELECT * FROM news");

  while ($row = mysql_fetch_array($result) ) &#123;

  echo($row&#1111;"id"] . "&nbsp;&nbsp;&nbsp;" . $row&#1111;"time"] . "&nbsp;&nbsp;&nbsp;" . $row&#1111;"subject"] . "&nbsp;&nbsp;&nbsp;" . $row&#1111;"content"] . "<br>");

  &#125;

?>
If I input

Hello
World!

It will output as "Hello World!"

Posted: Thu Dec 12, 2002 9:42 pm
by aybra
dumb question.. but did you chech your database to make sure the stuff added right? If the row or colomn is blank it well of course be blank.

Posted: Thu Dec 12, 2002 10:25 pm
by sclozza
Yep, just entered some sample data then

"testing!!!!
123"
(in that spacing / line configuration)

And ran the query from the mysql command line program, it output:

Code: Select all

mysql> select news from news where id=7;
+------------------+
| content          |
+------------------+
| testing!!!!
123 |
+------------------+
That looks right to me (it was the data I entered, and the line is in there), although should the formatting of the table be correct?

Thank you

Posted: Thu Dec 12, 2002 11:26 pm
by hob_goblin
Try this:

Code: Select all

<? 

  $time = $_POST&#1111;"time"]; 
  $subject = $_POST&#1111;"subject"]; 
  $news = $_POST&#1111;"news"]; 

  $dbcnx = @mysql_connect("localhost", "user", "pass") . 
  mysql_select_db("blog"); 

  $add = "INSERT INTO news (time, subject, content) VALUES ('$time', '$subject', '$news')"; 

  $added = mysql_query($add); 

  $test = mysql_connect("localhost", "root", "") or die ("Something's wrong"); 
  mysql_select_db("blog") or die ("Something is wrong"); 
  $result = mysql_query("SELECT * FROM news"); 

  while ($row = mysql_fetch_array($result) ) &#123; 

  echo(nl2br($row&#1111;"id"] . "   " . $row&#1111;"time"] . "   " . $row&#1111;"subject"] . "   " . $row&#1111;"content"] . "<br>")); 

  &#125; 

?>

Posted: Sat Dec 14, 2002 5:16 am
by sclozza
hob_goblin wrote:

Code: Select all

echo(nl2br($row&#1111;"id"] . "   " . $row&#1111;"time"] . "   " . $row&#1111;"subject"] . "   " . $row&#1111;"content"] . "<br>"));
Thank you very much, this fixed my problems. what does the nl2br do? I havent come across that in my reading.

PS, sorry about the delay in my reply, I have been busy and am sick :/

Posted: Sat Dec 14, 2002 8:20 am
by mydimension
in short, in appends a "<br />" onto every newline it encounters. read http://www.php.net/nl2br for more details

Posted: Sun Dec 15, 2002 1:19 am
by sclozza
mydimension wrote:in short, in appends a "<br />" onto every newline it encounters. read http://www.php.net/nl2br for more details
Very useful, thanks. I'll make a note of it

Posted: Sun Dec 15, 2002 1:19 am
by sclozza
oops, hit the button twice :/

Posted: Sun Dec 15, 2002 1:20 am
by oldtimer
A very nice tool indeed. I use it alot. Basically everytime you hit the enter key in a text field you get a \n for a new line. nl2br just calls it out as I am sure you have read about already.