Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
2  
yes.Keep just one column in database and insert new questions as new row –  vishal shah Nov 21 '13 at 9:40
 
Wrote an edit to clarify - sorry –  user1775598 Nov 21 '13 at 9:43
 
u can add user_id for user specific questions –  vishal shah Nov 21 '13 at 9:44
add comment

3 Answers

up vote 0 down vote accepted

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
 
I believe introducing another technology into the system for this purpose would be a grave mistake. ;) –  sam yi Nov 21 '13 at 15:23
 
@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? –  lakmal Nov 21 '13 at 17:07
 
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. –  sam yi Nov 21 '13 at 17:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.