This forum is no longer open and is for reading/searching only.
Please use our new MachForm Community Forum instead.
MachForm Community Forums » MachForm 2
Polls... how to show results
Started 16 years ago by ggmaury | 9 posts |
-
I just made a form to make a poll. The form works fine but I need to display the results with the total votes per choice and the percentage each one has.
I know I can export the values to xls or csv but I need to get them automaticly right after each vote.
Can you suggest any workaround?
Maybe updating the csv automaticly after casting a vote?Thanks
Posted 16 years ago # -
Sorry, I'm afraid I can't help much with this one, since it would require pretty much custom code.
MachForm Founder
Posted 16 years ago # -
Yuniar:
I achieved that by accessing the database and using form_id, position and option from ap_element_options table to select the form and then count the votes contained in element_1 (table ap_form1, ap_form2 and so on depending on the form number).
If works for a single multiple choice field and redirects to my results viewer.
check it out at:
http://campeche.com/encuestas/formas/view.php?id=1There are 4 forms so changong the id to 2, 3 or 4 you can see the others.
I just need to make a page with a menu of available polls to control the flow.
Posted 16 years ago # -
ooh.. that looks nice!
MachForm Founder
Posted 16 years ago # -
Can you elaborate a bit more on how you coded the results page?
Posted 16 years ago # -
I don't see anything except a blank screen with green background.....no poll or results there.
Posted 16 years ago # -
AMurray:
Sorry, I disabled that form.
You can check an example in http://campeche.com/encuestas/index.php?id_1=8&id_2=1&id_3=0&id_4=0girljinbink:
I made a machform directory where I use only 1 field multiple choice forms.
The machform db structure includes a table called 'ap_element_options' where field 'form_id' is the number of the form you want to show results from. All rows with the same 'form_id' will have different 'position' (or 'option_id' which have the same values). Each 'position' is a choice for the form.
By querying ($id is the form number passed in the url so the same script takes care of all polls):
$result = mysql_query("SELECT
position
,option
FROMap_element_options
WHEREform_id
= '$id'");you will get all rows with the same
form_id
thus getting all choices (choice number and name) of your poll:while ($row = mysql_fetch_array($result))
{
$choice[$total]['position'] = $row['position']; //choice number
$choice[$total]['option'] = $row['option']; //text describing choice
$choice[$total]['votes'] = 0; //will store total votes per choice$total++;
}At this point, you have a multidimentional array holding poll values.
Then you count the number of times (rows) each choice has been selected (I used a for loop based on $total). Those are saved in table 'ap_form_x' where 'x' is your 'form_id' and field
element_1
has the same value than 'option':$result = mysql_query("SELECT
element_1
, COUNT( * ) asvotes
FROM ".$apform." WHEREelement_1
='$i' GROUP BYelement_1
");$row = mysql_fetch_array($result);
$choice[$i]['votos'] = (int)$row['votes'];
$totalVotes = $totalVotes + $choice[$i]['votes'];then I sort the array based on total votes to show them from max to min votes.
From that point you display the results of your poll.
I hope that helps.
Posted 16 years ago # -
I'm at a beginning level of PHP, so although I understand most of what you're saying, there are some holes...
would you be willing to send me the code for your results page?
mjohnson(at)tcgrec.comPosted 16 years ago # -
ggmaury -
I am attempting to do the same thing that you did here several years back. That is, show instant results after a poll is submitted. Can you possible turn the example links back on or share your code? Thank you!
Posted 11 years ago #
Reply
You must log in to post.