开发者

ColdFusion Web Poll - Update poll results in MS Access Database

How can I code when option1 is selected to update access db with + 1 vote. Database only开发者_StackOverflow社区 has one record with Option1, Option2, Option3 & etc in each column. The total vote count will display under each column based on which option is choosen.


Database only has one record with Option1, Option2, Option3

The biggest problem is your table structure. Manipulating the data would be far easier if the options were stored in rows (not columns). For a very simple table, insert each option as a separate row, initialized with 0 votes:

   RecordID | OptionName | TotalVotes
   1        | T-Shirt 1  | 0 
   2        | T-Shirt 2  | 0 
   3        | T-Shirt 3  | 0 
   .... 
   5        | T-Shirt 5 | 0 

Then use the results of your SELECT query to populate your form (or display the totals if needed):

<cfoutput query="poll">
     <input type="radio" name="TshirtOption" value="#RecordID#"> #OptionName#
     ... 
</cfoutput>

When the form is submitted, increment the total votes for the selected option. Add validation of course.

<cfquery name="updateVote" datasource="fiteastpoll">
     UPDATE  Tshirt_poll
     SET     TotalVotes = TotalVotes + 1
     WHERE   RecordID = <cfqueryparam value="#form.TshirtOption#" cfsqltype="cf_sql_integer">
</cfquery>


I am assuming submitted option comes as form variable with name selectedOption and try below query...

<cfquery name="qUpdate" datasource="datasourcename">
Update TShirt_port set option#form.selectedOption# = option#form.selectedOption# + 1
</cfquery>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜