[PHP] Showing data with multiple lines from database

Status
Not open for further replies.

DeadBattery

Community Support Team
Community Support
Messages
4,018
Reaction score
120
Points
0
Hi!
I just started learning PHP today (I got through a lot :biggrin: ) but I ran into something that I don't know how to do.
I have the following code:
PHP:
<?php
$con = mysql_connect("localhost","root","********");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM person");

while($row = mysql_fetch_array($result))
  {
  echo $row['UserInput'];
  echo "<br />";
  }

mysql_close($con);
?>

However I have it so that UserInput has more than one line.
How do I echo more than one line?
Thanks! (I am planning on making my own CMS) :)
 

TechAsh

Retired
Messages
5,853
Reaction score
7
Points
38
Loop though them, I don't know. I would have though that all lines would be loaded.

One thing I do know is that mysqli is faster than mysql, I suggest using that instead.
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
I'm assuming you mean you want the newlines to be noticeable in the output. The newline characters are there(if you view the source you'll see them), but of course newlines have no real meaning in html. To solve this you need to use nl2br() on the string:

echo nl2br($row['UserInput']);
 

DeadBattery

Community Support Team
Community Support
Messages
4,018
Reaction score
120
Points
0
Thanks woiwky!
Now it is displaying the new lines properly. :)
 
Status
Not open for further replies.
Top