ColdFusion Web投票 - 更新MS Access数据库中的投票结果 [英] ColdFusion Web Poll - Update poll results in MS Access Database
问题描述
当选择option1时,如何用+ 1投票更新访问数据库。数据库只有一个记录与Option1,Option2,Option3&等等。总计投票计数将显示在每个列下,基于选择哪个选项。
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.
推荐答案
数据库只有一个记录
Option1,Option2,Option3
Database only has one record with Option1, Option2, Option3
最大的问题是您的表结构。如果选项存储在行(而不是列)中,则操作数据将会容易得多。对于非常简单的表,将每个选项作为单独的行插入,用0投票初始化:
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
然后使用SELECT查询的结果填充表单(如果需要, :
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>
这篇关于ColdFusion Web投票 - 更新MS Access数据库中的投票结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!