Page 1 of 1

Break lines with data from a DB Text Field

Posted: Mon May 16, 2005 1:40 am
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.

Posted: Mon May 16, 2005 2:04 am
by SBro
nl2br()

Code: Select all

<?=nl2br($data['pcomp']);?>

Work perfectly

Posted: Mon May 16, 2005 11:42 am
by rodsem
Thanks!