循环问题,如何写?马上给分!

lfaye 2004-07-25 11:55:16
http://www.xiaokang.com/bankofchina/
我就是想做上面的页面提交后的效果!写各位朋友可以写清楚一点吗?

假设礼品名称是:<%=RS("gift_name")%>,编号是<%=RS("pianhao")%>,页是<%=RS("page")%>,消费积分是:<%=RS("cost_jifen")%>,单价是:<%=RS("dajia")%>,数量:<input name="shuliang<%=rs("id")%>" type="text" id="shuliang<%=rs("id")%>">

一共两百分,如果回答得好的,请在下面回复一下,一起给分!
http://community.csdn.net/Expert/topic/3208/3208688.xml?temp=.2272608

提交后下一页怎样可以把客户输入的数据存到数据库?小弟对循环不是很熟,请大家不要见笑!
...全文
202 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
lfaye 2004-07-26
  • 打赏
  • 举报
回复
写错了,是:
但如果没有一个用户的ID存在又怎么能删除没有用不要的数据呢?
lfaye 2004-07-26
  • 打赏
  • 举报
回复
to:Jaron(唐伯虎点蚊香不烧香)

但是这里没有注册的用户,根本没有登录用户ID,你的意思是做一个临时表吗?但如果没有一个用户的ID存在又怎么能删除没有的数据呢?
Jaron 2004-07-26
  • 打赏
  • 举报
回复
conn.execute("insert into (userid,gift_id,amount)values(登录用户ID,'" & Args_Gift(i) & "','" & Args_amount(i) & "')

这里的 Args_Gift(i) 和 Args_amount(i),分别对应Gift的ID和用户填写的数量,将这些数据写进数据库里.
Jaron 2004-07-26
  • 打赏
  • 举报
回复
一个是商品表,一个是领取记录表

循环读出商品的ID和名称
do while ...
<input type=hidden name="gift_id" value="<%=rs_gifts("id")%>"><input type=text name=amount>
....
loop

取值:
gift_id = request("gift_id") '这里要过滤SQL非法字符,如单引号
amount = request("amount")
生成数组:
Args_Gift = split(gift_id,",")
Args_amount = split(amount,",")
if ubound(Args_Gift)<>ubound(Args_amount) then
表单读取错误,终止运行
end if
for i=0 to ubound(Args_Gift)
if Args_amount(i)<>"" then '如果没有填写,那么不写数据库
conn.execute("insert into (userid,gift_id,amount)values(登录用户ID,'" & Args_Gift(i) & "','" & Args_amount(i) & "')
end if
next


大致思路就是这样,程序自己写吧.
Jaron 2004-07-26
  • 打赏
  • 举报
回复
不需要临时表,如果不记录用户的ID,只记录各种赠品的申请情况的话,和上面的差不多


do while ...
<input type=hidden name="gift_id" value="<%=rs_gifts("id")%>"><input type=text name=amount>
....
loop

取值:
gift_id = request("gift_id") '这里要过滤SQL非法字符,如单引号
amount = request("amount")
生成数组:
Args_Gift = split(gift_id,",")
Args_amount = split(amount,",")
if ubound(Args_Gift)<>ubound(Args_amount) then
表单读取错误,终止运行
end if
for i=0 to ubound(Args_Gift)
if Args_amount(i)<>"" then '如果没有填写,那么不写数据库
conn.execute("insert into [赠品申请表] (gift_id,amount)values('" & Args_Gift(i) & "','" & Args_amount(i) & "')
end if
next
lfaye 2004-07-26
  • 打赏
  • 举报
回复
to: 唐伯虎

select sum(amount) from [table] group by gift_id where userid=用户ID '统计某用户
??????
那里还有userid呢?这里没有注册用户ID的.不记录用户的申请又怎样去到下一步页面呢?用临时表的话如果同时有两个人在线一齐填表,那读临时表不就有错误了吗?

现在关键是怎样跳到下一步啊..这个很重要
ycted 2004-07-26
  • 打赏
  • 举报
回复
其实就其那种页面的话,还用不找session.只要request就可以了,毕竟他不需要在多个页面来回的跑.就是post和request 商品id 商品name 商品数量 商品价格.
ycted 2004-07-26
  • 打赏
  • 举报
回复
你所提交过来的页面将商品的id记录下来,并累加,例如infoid=infoid&"/"&request("id")
然后在用
del = split(request("infoid"),",")
for each member in del
conn.execute("INSERT INTO titles
(title_id, title, type, pub_id, price)
VALUES ('BU9876', 'Creating Web Pages', 'business', '1389', '29.99') where id="& member &"")
next
lfaye 2004-07-26
  • 打赏
  • 举报
回复
session应该可以,不过应该用for来做吗?具体的语法应该怎样写?
现在就差这一步比较困难。。
ycted 2004-07-26
  • 打赏
  • 举报
回复
你可以用session保存每个物品.
比如:首先你对每个商品设定一个相对应的session,比如
在提交时,把没个物品用session记录 比如
趣致情侣杯: session("cup")=1 '1是代表你买了几个
迪卡龙礼盒: session("box")=2
这样你在提交后的页面判断每个session是否存在,比如session("cup")那么你就在商品的信息表里找到 趣致情侣杯 的相关信息,然后显示出来
lfaye 2004-07-26
  • 打赏
  • 举报
回复
能否写详细一点啊??小弟对ASP认识不深,能否写个例子来看看啊?感激不尽啦。。:)
Jaron 2004-07-26
  • 打赏
  • 举报
回复
收工,明天再来看你解决了没有...
kingapex1 2004-07-26
  • 打赏
  • 举报
回复
其实和够物车差不多 用session
可以参考:

http://blog.csdn.net/kingapex1/archive/2004/07/03/33013.aspx

Jaron 2004-07-26
  • 打赏
  • 举报
回复
如果你不需要的话,可以不记录用户的申请.需要记录的话,读出登录用户的ID就可以啦
做个视图做统计.或者:
select sum(amount) from [table] group by gift_id '统计某礼品的申请数
select sum(amount) from [table] group by gift_id where userid=用户ID '统计某用户申请礼品的详细情况

有个错误:

conn.execute("insert into [申请表的表名] (userid,gift_id,amount)values(登录用户ID,'" & Args_Gift(i) & "','" & Args_amount(i) & "')
mind_1220 2004-07-26
  • 打赏
  • 举报
回复
当然可以
你想能存放数据的容器都可以
除了数据库可以存放数据可以存放数据的多了
当然我建议使用xml
lfaye 2004-07-26
  • 打赏
  • 举报
回复
to Jaron(唐伯虎点蚊香不烧香)
有没有方法不写入数据库而进入下一步啊?

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧