Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Sep 2012
    Posts
    87
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Question Database table data not being displayed in right format on browser

    The contents of a mysql database table are being displayed as one continuous story without paragraphing (i.e. not being displayed in paragraphs). How do I correct the anomaly? Do I change the data types of the column or what? Note that the data is inserted into the database table via a html form. PLEASE HELP!

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Have a look at http://php.net/nl2br

    PS:
    Quote Originally Posted by http://www.codingforums.com/rules.htm
    1.2) Do not crosspost- CodingForums.com is divided into various categories. When initiating a thread, always locate the most appropriate category, and post your question only ONCE, in that category. Do not post the same question in multiple categories.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    Thuita Maina (09-07-2012)

  • #3
    New Coder
    Join Date
    Sep 2012
    Posts
    87
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Post

    Thanks Abduraooft for the reference and the PS: I will not crosspost again. I have however not grasped the use of nl2br() function. Where do I use it? Do I use it when I am inputting data into the database or when displaying in a browser? Below are the codes in my website that perform the aforementioned tasks (the particular table column I want paragraphed is in red). Please guide me on how I can make use of the nl2br() function.

    INSERTING:
    Code:
    $sessionvariable = $_SESSION['names'];
    $title = $_POST['title'];
    date_default_timezone_set('Africa/Nairobi');
    $datetime = date('Y/m/d H:i:s');
    $stories = $_POST['stories'];
    
    mysql_query("INSERT INTO  `a5846646_4f2005`.`stories` (
    `id` ,
    `names` ,
    `Title` ,
    `datetime` ,
    `stories`
    )
    VALUES (
    NULL ,  '$sessionvariable',  '$title',  '$datetime',  '$stories'
    )");
    RETRIEVING FOR DISPLAY ON BROWSER:

    Code:
    $id = $_GET['id']; 
    $sql = "SELECT * FROM `stories` WHERE `id` ='$id' ";  
      
    $result = mysql_query($sql) or die(mysql_error());  
      
    
     
        
            //display story data  
            while($row = mysql_fetch_assoc($result))  
            {  
                echo '<h2>Story title: ' . $row['title'] . '</h2><br>'; 
                echo '<h2>By: ' . $row['names'] .'</h2>'; 
                echo '<h2> on ' . $row['datetime'] . '</h2><br>';
                echo 'Story: ' . $row['stories'] . '<br>';   
            }
    Thank in advance for your assistance.

    Who said nothing is impossible while I have been doing nothing all this time?

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    PHP Code:
    echo 'Story: ' nl2br($row['stories']) . '<br>'
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    Thuita Maina (09-07-2012)

  • #5
    New Coder
    Join Date
    Sep 2012
    Posts
    87
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Thanks Abduraooft. It did it. Thanks for your thoughtful effort.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •