on my website I will be allowing users to insert text into multiple WYSIWYG(TinyMCE) text fields. Each field has a title which will be used for navigation and for general identification.
Whats being entered into the database:
Multiple: text from input (max 255 char)
Multiple: HTML/text from WYSIWYG Editor(no max set)
(could be as many as 20 or so text&textfield’s)
My Question is: What is a proper way to set up my database to handle the user generated content(should I make 20 columns for text or something other)? And in what form should I send it to the database(just lump it all into an array and send it to database or what)? And should I limit how much text can be in each textfield?
Using: Using phpMyAdmin
Also using CodeIgniter as my php framework
You left a lot of requirements unstated, so it’s hard to be specific.
But here’s what I would do if I were working in MySQL.
POST table:
POSTTEXT table
So, each post will have one row in POST, and zero or more rows in POSTTEXT. Most posts will have only one row in POSTTEXT, but extra long posts may have several. POSTTEXT.post_id is a foreign key pointing back to POST.post_id. posttext_id is a number that counts up from zero for each distinct post.
Why, you ask, not just put the posttext column in the POST table? Well, if you are sure you will never need to have your users page through very long posts, you can do this. Your schema will be a lot simpler. But if you’ll have a lot of hundred-thousand-word posts in the system where the user may want to view the nth page of text, then the two-table solution will work better.
This kind of thing will perform much better than a table with multiple text columns for multiple fields. In RDMS work, you’re almost always better off handling multiple similar rows than you are really wide rows with lots of columns.