1,105,409 Community Members

getting value from database and printing with \n

Member Avatar
hwoarang69
Posting Pro
572 posts since Feb 2012
Reputation Points: -4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 9 [?]
 
0
 

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
    ...
LastMitch
Deleted Member
 
4
 

@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";
Member Avatar
hwoarang69
Posting Pro
572 posts since Feb 2012
Reputation Points: -4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 9 [?]
 
0
 

it prints and puts enter at end of line.

color is red  size is large  random features1 random features2 \n
Member Avatar
urtrivedi
Posting Virtuoso
1,900 posts since Dec 2008
Reputation Points: 249 [?]
Q&As Helped to Solve: 409 [?]
Skill Endorsements: 27 [?]
 
1
 

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);
Member Avatar
hwoarang69
Posting Pro
572 posts since Feb 2012
Reputation Points: -4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 9 [?]
 
0
 

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

Member Avatar
urtrivedi
Posting Virtuoso
1,900 posts since Dec 2008
Reputation Points: 249 [?]
Q&As Helped to Solve: 409 [?]
Skill Endorsements: 27 [?]
 
1
 

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

Question Answered as of 1 Year Ago by urtrivedi and LastMitch
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article