[PHP] Showing data with multiple lines from database

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by DeadBattery, Jul 28, 2008.

Thread Status:
Not open for further replies.
  1. DeadBattery

    DeadBattery Community Support Team Community Support

    Messages:
    4,018
    Likes Received:
    120
    Trophy 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) :)
     
  2. TechAsh

    TechAsh Retired

    Messages:
    5,853
    Likes Received:
    7
    Trophy 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.
     
  3. woiwky

    woiwky New Member

    Messages:
    390
    Likes Received:
    0
    Trophy 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']);
     
  4. DeadBattery

    DeadBattery Community Support Team Community Support

    Messages:
    4,018
    Likes Received:
    120
    Trophy Points:
    0
    Thanks woiwky!
    Now it is displaying the new lines properly. :)
     
Thread Status:
Not open for further replies.

Share This Page