Click to See Complete Forum and Search --> : Poll Casting


xesojay
02-14-2005, 04:41 AM
Hi Guys,
Am devloping a page where people will be able to vote based on the question that I put on the page.Now, the problem now comes from how I will display the result of each options based on their number of vote. Then later convert it to percentage.
Please I have no clue on how to display the result. I need your help, you can just give me a clue but if you can provide the full code I will be glad.

russell
02-15-2005, 12:11 AM
Assuming you are using a database for this, you probably should have 2 tables (for a very basic illustration), that might look like this:
Table: Questions

ID Question_Text
-- -------------
1 first question here
2 second question here

Table: Poll

Question_Id Response
----------- --------
1 1
1 1
1 0

where a response to question 1 is inserted into the Poll table.

Now you could use a query like this to show results:

SELECT Response, Count(Response) as cnt
FROM Poll
WHERE Question_Id = 1
GROUP BY Response
ORDER BY Response
This would return 2 records (from the sample data above) that would look like this
Response cnt
-------- ---
0 1
1 2

So you can loop through the recordset and sum the count (giving 3), then divide the individual results to get the percentage

Does that put you on the right track? post back if u need more...