I’m working with PHP and MySQL, and I’m not too experienced with database design. I know the basics of normalization, however my question is about storing vales from a specific form I have.
Ok, so the way my page in question is set up, there are text boxes that can be dynamically added or removed. If the user presses a “+” or “-” button it adds or removes another text box.
Anyway, when I pull the text box values via $_POST it is an array, and then I convert it to a string using implode() Ex: user enters “hello” “world” “bye” “world”, implode converts it to the following string “hello,world,bye,world”.
My question is would it be better to store this string “hello,world,bye,world” in 1 row as 1 entry, or would it be better to break this string into 4 separate strings and store it in 4 different rows? Each text box will contain questions/comments so they could be potentially long and most likely not 1 word like the example I gave.
The reason why I’m asking this is because all of these inputs will be used on the same page, so they can all share a unique ID. Instead of querying multiple times, I’d only have to query once.
They should be stored separately, because they’re separate examples of one kind of data.
Your table would be (for example)
comments, and each row should be one comment, so one row forhello, one forworld, etc.You could also store a page ID alongside the comments, so your table would look like this (note that you’d typically have an
idfield for comment id, as well. I’ve omitted it for brevity):Then you can still search on page_id, but your data is logically separated, and you can search on the specific comments if you wish.
You can also do things like ordering it alphabetically, or by time (with a new column for that) very easily.