请解释下这段ASP代码的意思

dim Action,ID,VoteType,VoteOption,arrOptions,sqlVote,rsVote
dim Voted,VotedID,arrVotedID,i
dim FoundErr,ErrMsg

VoteOption=trim(request("VoteOption"))

if instr(VoteOption,",")>0 then
arrOptions=split(VoteOption,",")
for i=0 to ubound(arrOptions)
conn.execute "Update Vote set answer" & cint(trim(arrOptions(i))) & "= answer" & cint(trim(arrOptions(i))) & "+1 where id=4"
next
else
conn.execute "Update Vote set answer" & VoteOption & "= answer" & VoteOption & "+1 where id=4"
end if

if err then
response.Write("<script language=javascript>alert('保存失败');location='试验.asp';</script>")
else
response.Write("<script language=javascript>alert('保存成功');location='试验.asp';</script>")
end if
上一页是:
<form action="shiyan_vot.asp" method="post">
<table width="200" border="1">
<tr>
<td><input name="VoteOption" type="checkbox" value="1" />123</td>
</tr>
<tr>
<td><input name="VoteOption" type="checkbox" value="2" />143</td>
</tr>
<tr>
<td><input name="VoteOption" type="checkbox" value="3" />444</td>
</tr>
<tr>
<td><input name="VoteOption" type="checkbox" value="4" />555</td>
</tr>
<tr>
<td><input name="VoteOption" type="checkbox" value="5" />666</td>
</tr>
<tr>
<td><input name="" type="submit" /></td>
</tr>
</table>
</form>
如果FORM中没选的话,是怎么剔除的。上面的代码是怎么遍历数组的,那些是数组的内容,例:(内容1,内容2);那些是数组的排名(第一字段,第二字段),最好详细点,怎么进数据库的,能多说就多说点,详细的有加分 ,提示answer1、2、3是数据库里计数的字段,选择了就加1

第1个回答  推荐于2016-05-01
复选框提交后,浏览器会将所有选中的复选框内容合到一起,统一由VoteOption传递。
为了区分各个复选框内容,格式是“复选框内容1, 复选框内容2, .....”,其实就是用逗号+一个空格来隔开。

asp部分接收后用instr(VoteOption,",")来检查是否含有逗号,>0表示有逗号,说有几个复选框的内容在里面。

接着用split(VoteOption,",")函数通过逗号做分割将VoteOption内的文本拆分成数组。

for i=0 to ubound(arrOptions) 循环这个数组啦

conn.execute "Update Vote set answer" & cint(trim(arrOptions(i))) & "= answer" & cint(trim(arrOptions(i))) & "+1 where id=4"
循环一次执行一次conn.execute()写入数据库,arrOptions(i)就是数组第i个值,比如i=1,就是数组第1个值。本回答被提问者采纳
第2个回答  2009-02-19
if instr(VoteOption,",")>0 then '判断变量voteOption中是否包含“,”大于0表示包含“,”字符
arrOptions=split(VoteOption,",")'split(VoteOption,",")遍历数组分隔符是","
for i=0 to ubound(arrOptions) 'ubound(arrOptions) 获取arrOptions数组的最大下标
相似回答