In my system a manager create a poll and publish it to the world so users which have the link to the poll can answer it.
There is some question which designed to receive multiple answers, so user can choose multiple distract in one response.
The response table structure in the DB
- ID
- ActivityID – the poll ID
- Value – the district value
- TimeResponse
In the database i am currently saving each response separately.
I will give you an example
Lets say there is 4 district in a poll (a,b,c,d)
User choose the following district (a,b,c)
The response table will look like this:
ID ActivityID Value TimeResponse
1 234 a 01/01/2012
2 234 b 01/01/2012
3 234 c 01/01/2012
So if i try to count the ID i will get the number 3 which represent the number of district were answered is a given poll.
BUT i need the number of responses per user in a given poll, so i need somehow to combine those two…
Until now i thought about the following solutions but neither of them is good.
- the first solution was to add a column of the user’s IP, but sometimes i cant get the user’s IP.
- the second solution was to add a column of the user’s sessionID using the sessionIDManager, but if the user answer twice (2 response) it will store the same session ID.
FYI, the user which answer the poll is anonymous.
And also one of the system requirement is to allow a user to answer a poll several times
There are two approaches I can see.
One would be to generate a UUID every time the user answers the poll. Create a column within the database, such as AnswerID and use this same UUID when you’re creating the rows for each of their responses. In C#, you can create a UUID with
Guid.NewGuid(). You could then count the number of responses by querying for the distinct AnswerID values.The second approach would be to use a single row for each set of answers to a given question. For example, if the user answered A, B and C, you’d store the response as “A/B/C”. This would make it harder to query for the total number of a certain answer, though some database systems might make this easier (for example, PostgreSQL has an indexable array type).
Hope this helps!