We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,695 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

getting value from database and printing with \n

i hava a col in database called "features" and its type "text".

some where in my website page i have a textarea. where user can list features. here is a ex:
lets say below is a text area and user is entering features. at end of line is enter

<textarea type="text" name="fea" > 
    -----------------------------------
    color is red.
    size is large.
    random features1
    random features2
    etc...
    -----------------------------------
</textarea>

now calling name='fea' and storeing value in database 'features'. here is how 'features' look like in database:

features: color is red
          size is large 
          random features1
          random features2

now i am getting the value of features from database

$item_query = mysql_query("SELECT * FROM item"); 
$row = mysql_fetch_assoc($item_query)
$features_db = $row['features'];

here is the problem is. when i echo'$features_db'; it doesnt prints the enters. so for ex it print this:

 color is red  size is large  random features1 random features2

but i want to print in a nice list like this

  • color is red
  • size is large
  • random features1
    ...
3
Contributors
5
Replies
3 Hours
Discussion Span
5 Months Ago
Last Updated
6
Views
Question
Answered
hwoarang69
Posting Pro
569 posts since Feb 2012
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 7

@hwoarang69

here is the problem is. when i echo'$features_db'; it doesnt prints the enters. so for ex it print this:

Instead of this

echo'$features_db';

Try to add this:

echo "$features_db\n";
LastMitch
Industrious Poster
4,118 posts since Mar 2012
Reputation Points: 132
Solved Threads: 334
Skill Endorsements: 45

it prints and puts enter at end of line.

color is red  size is large  random features1 random features2 \n
hwoarang69
Posting Pro
569 posts since Feb 2012
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 7

how it is stored in mysql, Is it in one column one row, or all features are in separte record?

If it is strored using textarea (with user manually breking line in textarea) then following trick may work, no need of \n

echo nl2br($features_db);
urtrivedi
Posting Virtuoso
1,714 posts since Dec 2008
Reputation Points: 299
Solved Threads: 362
Skill Endorsements: 24

awesome got it to working. so nl2br takes \n from textarea?

hwoarang69
Posting Pro
569 posts since Feb 2012
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 7

that function if finds new line in string, it renders it to html <br> tag.

urtrivedi
Posting Virtuoso
1,714 posts since Dec 2008
Reputation Points: 299
Solved Threads: 362
Skill Endorsements: 24
Question Answered as of 5 Months Ago by urtrivedi and LastMitch

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0958 seconds using 2.69MB