ColdFusion Web投票 - 更新MS Access数据库中的投票结果(ColdFusion Web Poll - Update poll results in MS Access Database)

高性能WEB开发 IT屋
问 题

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.

解决方案

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>

本文地址:IT屋 » ColdFusion Web Poll - Update poll results in MS Access Database

问 题

当选择option1时,如何用+ 1投票更新访问数据库。数据库只有一个记录与Option1,Option2,Option3&等等。总计投票计数将显示在每个列下,基于选择哪个选项。


解决方案

数据库只有一个记录
Option1,Option2,Option3




最大的问题是您的表结构。如果选项存储在行(而不是列)中,则操作数据将会容易得多。对于非常简单的表,将每个选项作为单独的行插入,用0投票初始化:



  RecordID | OptionName | TotalVotes 
1 | T恤1 | 0
2 | T恤2 | 0
3 | T恤3 | 0
....
5 | T恤5 | 0


然后使用SELECT查询的结果填充表单(如果需要, :



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


提交表单时,增加所选选项的总投票。当然添加验证。



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

本文地址:IT屋 » ColdFusion Web投票 - 更新MS Access数据库中的投票结果