0

I've got a page with text fields where the user can input data (in our situation they are questions).

It would look look something like this:

 ___________________________________
|   Enter your question...          |  +
|___________________________________|  

If the user clicks '+' then another field comes up:

 ___________________________________
|   User's first Question..         | 
|___________________________________|  
 ___________________________________
|   Enter your next question...     |  +
|___________________________________|  

...And so on. Each of these questions need to be stored in the database, but with the number of questions being dynamic (let's say for arguments sake we limit the max number to 100 questions), what's the best way to achieve this? Should I be creating a new column for each question? Wouldn't that really pollute the database? Ideally I'd have just one column in my database called 'Questions' and just store all the questions in that one column. Is that even possible?

Something like this:

++++++++++++++++++++++++++++++++++++++++++++++
+ id |  Questions                            +
++++++++++++++++++++++++++++++++++++++++++++++
+  1 |  My Question 1,MyQuestion,            +
+  2 |  Another Question, And Another one,   +
+  . |  ......                               +
++++++++++++++++++++++++++++++++++++++++++++++

*EDIT* To make it clear - I need to be able to retrieve each of those questions later on and be able to isolate each one individually (e.g. as a PHP array).

*EDIT2* Additionally because the set of questions are per each user, the bundle of questions need to remain in ONE row. I.e. I can't add the questions in their own rows. In the example above, ID1 is an individual user and My Question 1 and MyQuestion are that user's questions.

3
  • 2
    yes.Keep just one column in database and insert new questions as new row Commented Nov 21, 2013 at 9:40
  • Wrote an edit to clarify - sorry Commented Nov 21, 2013 at 9:43
  • u can add user_id for user specific questions Commented Nov 21, 2013 at 9:44

3 Answers 3

1

The simplest one, I believe, is to made your database table like this :

++++++++++++++++++++++++++++++++++++++++++++++
+ id | user_id | question                    +
++++++++++++++++++++++++++++++++++++++++++++++

So it does not matter how many question a user will have.

Sign up to request clarification or add additional context in comments.

Comments

0

An option you can try as well would be to split it up by creating another table. So to be clear one table for user and another one for question.

In table user you can have a user_id and maybe username and in table question you can have a unique_id, the question and then a foreign key constraint referencing the user of the question.

This way you can access them individually or all together.

Comments

0

In this situation, you can use Document based NOSQL solution like MongoDB, or create a table with id , user_id and question.

3 Comments

I believe introducing another technology into the system for this purpose would be a grave mistake. ;)
@sam yi,No because these questions and answer are looking by not only who posted the question.Questions from Stackoverflow may reffer by many IT students. So we have responsibility to add some additional but relevent information when we are answering. is it?
Even if that were the case. NoSQL is really for the edge case scenarios where relational databases fall short. I know a lot of developers are like kids and they want to get their hands on anything new and cool but in an enterprise world where we still rely heavily on AS/400 systems, these "cool" toys come and go. Not saying NOSql is useless... just saying there's a bit too much hype.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.