Break lines with data from a DB Text Field

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
rodsem
Forum Newbie
Posts: 5
Joined: Mon May 16, 2005 1:21 am

Break lines with data from a DB Text Field

Post by rodsem »

Hi. I want to know how to generate the break lines in a paragraph, where I'm taking the information from a data of a mySQL Text Field in my database.

I made all the conection and it's working perfectly. To retrieve the data I'm using this code:

Code: Select all

<?php
			$infoprods = mysql_query("SELECT * FROM prods WHERE prod_id=$pid",$link);
			$g = mysql_query("SELECT gname FROM grupos WHERE grupo_id=$gid",$link);
			$l = mysql_query("SELECT lname FROM lineas WHERE linea_id=$lid",$link);
			$data = mysql_fetch_array($infoprods);
			$datagrupo = mysql_fetch_array($g);
			$datalinea = mysql_fetch_array($l);
		?>
And then I print the information using this code:

Code: Select all

<?=$data['pcomp'];?>
My problem is that the result is a continues line of text like this:

IVU. Prostatitis. ETS (gonorrea, chancroide, uretritis por clamyda). Infecciones gastrointestinales....

But in the DB it's stored like:

IVU.
Prostatitis.
ETS (gonorrea, chancroide, uretritis por clamyda).
Infecciones gastrointestinales......

So, how can I make that the displayed data look like the stored one?

Can anyone help me! I have a presentation of a website and I don't know how to solve this.
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

Post by SBro »

nl2br()

Code: Select all

<?=nl2br($data['pcomp']);?>
rodsem
Forum Newbie
Posts: 5
Joined: Mon May 16, 2005 1:21 am

Work perfectly

Post by rodsem »

Thanks!
Post Reply