| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 740 人关注过本帖
标题:投票统计
只看楼主 加入收藏
xuli
Rank: 1
等 级:新手上路
帖 子:54
专家分:0
注 册:2004-8-24
收藏
 问题点数:0 回复次数:4 
投票统计
学校要做一个投票统计,但为了面子又不想让人家看见统计结果,让我来做这个活。虽然我水平不高但想着也不是太麻烦的事情,我就这样做了:第一个页面index.html放投票的表单,三个单选按钮“很好”、“一般”、“差”分别命名为bt1、bt2、bt3,当点击投票按钮以后进入count.asp,在这个文件里判断bt1、bt2、bt3中哪一个传过来的数值不为空则将对应的数据库里的“很好”“一般”“差”的记数加一,修改完数据库后自动掉转回index.html。再加一个look.asp的页面能读取数据库里的数值就行了。但是我碰到了一个问题:数据库的数据始终不增加。我不知道哪里错了。请大家帮忙看看,水平不高请不要笑话。
<!--# include file="conn.asp"-->
<%
dim a,b,c,d,e,f,g,h,i
d=0
e=0
f=0
a=request.form("bt1")
b=request.form("bt2")
c=request.form("bt3")
set conn=server.createObject("ADODB.Connection")
conn.open "driver={Microsoft Access Driver (*.mdb)};dbq=" & server.MapPath("1.mdb")
set rs=server.CreateObject("ADODB.Recordset")
rs.open "count",conn,1,3
if a<>"" then d=1
if a<>"" then e=1
if a<>"" then f=1
g=rs("good")
g=g+d
rs("good")=g
h=rs("good")
h=h+e
rs("good")=h
i=rs("good")
i=i+f
rs("good")=f
rs.update
rs.close
set rs=nothing
response.redirect "index.html"
%>

[此贴子已经被作者于2005-1-7 12:37:39编辑过]


搜索更多相关主题的帖子: 投票 统计 
2005-01-07 12:35
regedit
Rank: 5Rank: 5
等 级:贵宾
威 望:19
帖 子:950
专家分:0
注 册:2004-6-8
收藏
得分:0 
if a<>"" then d=1
if a<>"" then e=1
if a<>"" then f=1
这里怎么没有end if?

g=rs("good")
g=g+d
rs("good")=g
h=rs("good")
h=h+e
rs("good")=h
i=rs("good")
i=i+f
rs("good")=f
这里转来转去,因为始终都没有更新,所以前面的rs("good")=g之类的就没有意义!

其实可以简化为:
<!--# include file="conn.asp"-->
<%
dim conn,rs
dim a,b,c
set conn=server.createObject("ADODB.Connection")
conn.open "driver={Microsoft Access Driver (*.mdb)};dbq=" & server.MapPath("1.mdb")

a=request.form("bt1")
b=request.form("bt2")
c=request.form("bt3")
  if a<>"" then
    conn.execute("update count set bt1=bt1+1")   '更新a字段的值为+1
  end if
  if b<>"" then
    conn.execute("update count set bt2=bt2+1")   '更新b字段的值为+1
  end if
  if c<>"" then
    conn.execute("update count set bt3=bt3+1")   '更新c字段的值为+1
  end if
response.redirect "index.html"
%>

最新作品:百货品牌商品资讯第一门户([url]http://www./[/url]),欢迎交流
2005-01-07 12:53
xuli
Rank: 1
等 级:新手上路
帖 子:54
专家分:0
注 册:2004-8-24
收藏
得分:0 
非常感谢!
我看过的几个书上的例子里都没有说过更新字段值。谢谢regedit,我学会了这个语句了。程序调试下来很好。
我还想问一下:我上面的程序里不是在最后写了rs.update了吗,为什么它不起作用?我的书上有添加记录的例子,上面就有像这样的一个程序片段:
if no<>"" then
rs.addnew
rs("学号")=no
rs("姓名")=name
rs.update
end if
为什么这样的一个程序片段就能起作用,而我写的就不能起作用呢?

2005-01-07 13:23
regedit
Rank: 5Rank: 5
等 级:贵宾
威 望:19
帖 子:950
专家分:0
注 册:2004-6-8
收藏
得分:0 
g=rs("good")
g=g+d
rs("good")=g
h=rs("good")
h=h+e
rs("good")=h
i=rs("good")
i=i+f
rs("good")=f
这里只有最后面的rs("good")=f 才是最终写入数据库的,前面的都只是赋值而且是赋给同一个值!,而最终都没有做update来更新,所以不起作用!
而if no<>"" then
rs.addnew
rs("学号")=no
rs("姓名")=name
rs.update
end if
这里是赋不同字段的值,没有重复!,所以更新就会起作用啊~

最新作品:百货品牌商品资讯第一门户([url]http://www./[/url]),欢迎交流
2005-01-07 13:48
xuli
Rank: 1
等 级:新手上路
帖 子:54
专家分:0
注 册:2004-8-24
收藏
得分:0 
懂了。谢谢!

2005-01-07 14:23
快速回复:投票统计
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015335 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved