PDA

View Full Version : Text Area with sql format issues


macleodjb
11-15-2008, 11:30 PM
Hi all,

this is probably a simple solution. Actually a multi-part question.

I have a text area that will be filled with alot of text that i want to save to my sql database. I am having two problems or issues. First problem is that when it gets saved to the sql database it loses all of its formatting such as indents and paragraph break, list elements and that such. How can i get it to retain those properties?

Secondly i am using varchar(2000) as my field type. Should i be using something else to handle large amounts of text better? I'm not too familiar with the other types.

Thanks in advance.

Fumigator
11-17-2008, 07:13 PM
Prior to version 5.03, varchar() is limited to 255 characters. I guess I should assume you are using >= version 5.03.

Assuming so, you may as well define it as varchar(65535) which is the largest a varchar can get; anything smaller doesn't waste any storage space so it's not a big deal.

The first issue is resolved by storing the HTML tags that format the text. Keep in mind that a new line is stored in the data as \n, and you have to convert that \n to a <br> for the \n to show up in a browser (browsers don't pay any attention to \n). PHP has a function to do that easily: nl2br().