Hi
I wrote a php program that shows a poll and people have to vote for it
theres a table in my mysql database for polls:
polls columns:
pollquestion
polloptions
pollvotes
pollvoters
voterschoices

pollquestion column will contain the question of the poll
polloptions will contain all the options for the poll (divided by the sign |)
pollvotes will contain the numbers of the votes of each option respectively..
For example, if the polloptions contained: Option 1 | Option 2 | Option 3
and pollvotes contained: 3 | 50 | 6
that means that the Option 1 got 3 votes, and the Option 2 got 50 votes, and the Option 3 got 6 votes and so on...
pollvoters column will contain the names of the voters; each time a user votes his name will be inserted in the column using the concat function..
voterschoices column will contain the choices of the voters.. each choice will be represented by its Order number (Option 1 will have num 1, Option 3 will have num 3...)

Now how can I write a php code to show what each user has voted?
I wrote a code to do it but it was very bad because it shows a list of users and in front of them it shows their choices.. I want the program to show options and the choices of the users for each option.. for example:
Option 1: John, Selim, Khaled, etc.. (Where these are the names of voters).

Thanks in advance.

Can't you just select the amount of votes that an option has received from the pollvotes column, and then display the result behind the poll option?

I dont mean that
What I mean is this:
Each option should be viewed and in front of it should be the voters who chose that option

This depends on how you're storing pollvotes . Regardless, you could store it in a variable as a string or array, then echo it to the results page.

Regards
Arkinder

Member Avatar for diafol

This is awkward

How about:

[B]users[/B]
user_id (PK)...

[B]polls[/B]
poll_id (PK), poll_title, poll_question...

[B]poll_options[/B]
poll_op_id (PK), poll_id (FK), poll_op_text...

[B]poll_results[/B]
user_id (FK), poll_op_id (FK)  AS composite PK

normalized. dealing with serialised lists in single fields is difficult

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.