Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-07-2012, 07:19 AM   PM User | #1
Thuita Maina
New Coder

 
Join Date: Sep 2012
Posts: 76
Thanks: 10
Thanked 0 Times in 0 Posts
Thuita Maina is an unknown quantity at this point
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!
Thuita Maina is offline   Reply With Quote
Old 09-07-2012, 09:48 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
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.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Users who have thanked abduraooft for this post:
Thuita Maina (09-07-2012)
Old 09-07-2012, 10:24 AM   PM User | #3
Thuita Maina
New Coder

 
Join Date: Sep 2012
Posts: 76
Thanks: 10
Thanked 0 Times in 0 Posts
Thuita Maina is an unknown quantity at this point
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.

Quote:
Who said nothing is impossible while I have been doing nothing all this time?
Thuita Maina is offline   Reply With Quote
Old 09-07-2012, 10:56 AM   PM User | #4
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
PHP Code:
echo 'Story: ' nl2br($row['stories']) . '<br>'
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Users who have thanked abduraooft for this post:
Thuita Maina (09-07-2012)
Old 09-07-2012, 11:34 AM   PM User | #5
Thuita Maina
New Coder

 
Join Date: Sep 2012
Posts: 76
Thanks: 10
Thanked 0 Times in 0 Posts
Thuita Maina is an unknown quantity at this point
Thanks Abduraooft. It did it. Thanks for your thoughtful effort.
Thuita Maina is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:00 PM.


Advertisement
Log in to turn off these ads.