ColdFusion Web Poll - Update poll results in MS Access Database

杀马特。学长 韩版系。学妹 提交于 2019-12-25 05:19:21

问题


How can I code when option1 is selected to update access db with + 1 vote. Database only 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.


回答1:


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>



回答2:


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>


来源:https://stackoverflow.com/questions/6596339/coldfusion-web-poll-update-poll-results-in-ms-access-database

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!