Text display problem.

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
Nicoza
Forum Newbie
Posts: 11
Joined: Mon Oct 02, 2006 11:43 am

Text display problem.

Post by Nicoza »

My Site is published at a hosting company. MySQL, PHP the works is available. Site management is done through Plesk, and data maintenance through PHPMyAdmin. Everything works well.

I have a table called say “ARTICLES” in die db called “MYDB” with a number of fields. The applicable field is where the actual article will be placed. This is called “ARTICLE” and of type TEXT. There is an option (which might be applicable later) called Attributes with 3 options: Binary, unsigned, and unsigned zero, which I don’t know what for. But, at the moment it is blank.

Now, I access the Database through my php code without any hassles. A make additions to the database without any problem.

Basically, I have an HTML form:

Code: Select all

<form action="addarticle.php" method="post">
<textarea rows="10" name="art" cols="50"></textarea>
<input type="submit" value="Ok" name="add">
</FORM>


This works well. Then add the data to the DB:

Code: Select all

$SQL = "INSERT INTO ARTICLES VALUES ('$art')";


At this point all is well. Then In another script I extract the data:

Code: Select all

$SQL = "SELECT ARTICLE FROM ARTICLES";
$RESULT = mysql_query($SQL);
			
if (!$RESULT) 
{
die('Could not retrieve data: ' . mysql_error());
}

Then display it:

Code: Select all

while ($ROW = mysql_fetch_assoc($RESULT)) 
{
echo $ROW["ARTICLE"];
}

Still, it works fine. But the problem is, even though the data was typed by the user using paragraph breaks (enter) and so on, it does not display as such. In stead it’s all just one continues paragraph. I checked to see if the problem was done in my INSERT phase, but viewing the data in PHPMyAdmin, it is fine and printed in paragraphs. Therefore, the problem must be at the representation part:

Code: Select all

Echo $ROW[“ARTICLE”];
Is there some form of way I should format the DB result before printing it? By the way, I do not print it in a text box again, just simply in my HTML page, in a cell of a table.

I’m sure this is something simple for you guys.

Thanks for the time.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

The line breaks will be there in your HTML source but the browser ignores them. Use nl2br() to turn them in to <br /> tags ;)
Nicoza
Forum Newbie
Posts: 11
Joined: Mon Oct 02, 2006 11:43 am

Text display problem.

Post by Nicoza »

Yip, knew it's going to be simple.

Thanks for the quick reply d11wtq.
Post Reply