1.11M Members

getting value from database and printing with \n

 
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";
 
0
 

it prints and puts enter at end of line.

color is red  size is large  random features1 random features2 \n
 
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);
 
0
 

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

 
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
Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article