New line

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sclozza
Forum Newbie
Posts: 14
Joined: Wed Oct 09, 2002 5:11 am

New line

Post 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.
aybra
Forum Commoner
Posts: 56
Joined: Sun Nov 24, 2002 12:52 am

Post by aybra »

? what is the actual code your using?
sclozza
Forum Newbie
Posts: 14
Joined: Wed Oct 09, 2002 5:11 am

Post 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!"
aybra
Forum Commoner
Posts: 56
Joined: Sun Nov 24, 2002 12:52 am

Post 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.
sclozza
Forum Newbie
Posts: 14
Joined: Wed Oct 09, 2002 5:11 am

Post 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
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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; 

?>
sclozza
Forum Newbie
Posts: 14
Joined: Wed Oct 09, 2002 5:11 am

Post 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 :/
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

in short, in appends a "<br />" onto every newline it encounters. read http://www.php.net/nl2br for more details
sclozza
Forum Newbie
Posts: 14
Joined: Wed Oct 09, 2002 5:11 am

Post 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
sclozza
Forum Newbie
Posts: 14
Joined: Wed Oct 09, 2002 5:11 am

Post by sclozza »

oops, hit the button twice :/
Last edited by sclozza on Sun Dec 15, 2002 1:21 am, edited 1 time in total.
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post 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.
Post Reply