预览效果:
<!--#include file="conn.asp"--> <% '获取字符串在数组中的位置 function getN(x,y) getN=0 arr=split(x,",") for i=0 to ubound(arr) if arr(i)=y then getN=i+1 exit function end if next end function '获取够买商品的商品编号、尺码、颜色、数量 ProdId=request("ProdId") mychima=request("mychima") myyanse=request("myyanse") shuliang=request("shuliang") action=request("action") '清空购物车 if action="cleargouwuche" then Response.Cookies("gouwuche")("ProdId")="" Response.Cookies("gouwuche")("mychima")="" Response.Cookies("gouwuche")("myyanse")="" Response.Cookies("gouwuche")("shuliang")="" end if if Request.Cookies("gouwuche")("ProdId")="" or Request.Cookies("gouwuche")("ProdId")="''" then '当购物车中没有任何商品 Response.Cookies("gouwuche")("ProdId")="'"&ProdId&"'" Response.Cookies("gouwuche")("mychima")=mychima Response.Cookies("gouwuche")("myyanse")=myyanse Response.Cookies("gouwuche")("shuliang")=shuliang elseif ProdId<>"" then '当购物车中已经有商品 Response.Cookies("gouwuche")("ProdId")=Request.Cookies("gouwuche")("ProdId")&","&"'"&ProdId&"'" '将购买的商品的编号用“,”隔开 Response.Cookies("gouwuche")("mychima")=Request.Cookies("gouwuche")("mychima")&","&mychima '将购买的尺码的编号用“,”隔开 Response.Cookies("gouwuche")("myyanse")=Request.Cookies("gouwuche")("myyanse")&","&myyanse '将购买的颜色的编号用“,”隔开 Response.Cookies("gouwuche")("shuliang")=Request.Cookies("gouwuche")("shuliang")&","&shuliang '将购买的商品的数量用“,”隔开 end if '将购物车中商品的尺码、颜色、数量分别放入数组中 mychimaarr=split(Request.Cookies("gouwuche")("mychima"),",") myyansearr=split(Request.Cookies("gouwuche")("myyanse"),",") shuliangarr=split(Request.Cookies("gouwuche")("shuliang"),",") '删除商品 if action="delshangpin" then delid="'"&request("delid")&"'" '获取要删除商品的商品编号 delN=getN(Request.Cookies("gouwuche")("ProdId"),delid) '获取要删除商品的商品编号在所选购商品编号字符串中的位置 Response.Cookies("gouwuche")("ProdId")=replace(Request.Cookies("gouwuche")("ProdId"),delid,"") '以下8行的作用是删除所选购商品编号字符串中要删除商品的商品编号 Response.Cookies("gouwuche")("ProdId")=replace(Request.Cookies("gouwuche")("ProdId"),",,",",") if left(Request.Cookies("gouwuche")("ProdId"),1)="," then Response.Cookies("gouwuche")("ProdId")=replace(Request.Cookies("gouwuche")("ProdId"),",","",1,1) end if if right(Request.Cookies("gouwuche")("ProdId"),1)="," then Response.Cookies("gouwuche")("ProdId")=replace(Request.Cookies("gouwuche")("ProdId"),",","",len(Request.Cookies("gouwuche")("ProdId"))-1,1) end if mychimaarr=mychimaarr.splice(delN,1) '从尺码数组中删除要删除商品的尺码 myyansearr=myyansearr.splice(delN,1) '从颜色数组中删除要删除商品的颜色 shuliangarr=shuliangarr.splice(delN,1) '从数量数组中删除要删除商品的数量 Response.Cookies("gouwuche")("mychima")=Join(mychimaarr,",") '删除商品后将剩余商品的尺码用“,”隔开 Response.Cookies("gouwuche")("myyanse")=Join(myyansearr,",") '删除商品后将剩余商品的颜色用“,”隔开 Response.Cookies("gouwuche")("shuliang")=Join(shuliangarr,",") '删除商品后将剩余商品的颜色用“,”隔开 end if if Request.Cookies("gouwuche")("ProdId")="" or Request.Cookies("gouwuche")("ProdId")="''" then '当购物车中没有任何商品 response.Write("<script language='javascript'>alert('购物车中还没有任何商品!');window.location.href='cat.asp';</script>") response.End() end if '查询购物车中的商品 set rs=server.CreateObject("adodb.recordset") sql="select * from bproduc where ProdId in ("&Request.Cookies("gouwuche")("ProdId")&")" rs.open sql,conn,3,2 '查询当前会员的会员级别 Set rstxt = conn.Execute("select * from buser where userid='"&request.cookies("www3gushopcom")("userid")&"'") UserType=rstxt("UserType") set rstxt=nothing '获取不同会员级别的折扣 Function zhikou(UserType) set zhikouRs=server.CreateObject("adodb.recordset") zhikouSql="select kou"&UserType&" from bconfig" zhikouRs.open zhikouSql,conn,3,1 zhikou=zhikouRs("kou"&UserType) zhikouRs.close set zhikouRs=nothing End Function %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>购物车</title> <link href="/images/88kaya/CSS.css" rel="stylesheet" type="text/css" /> </head> <body> <table width="960" border="1" align="center" cellpadding="8" cellspacing="1" bordercolor="#DCDFE5" style="margin-top:10px; border-collapse:collapse;"> <tr style="color:#FFFFFF;"> <td width="60" align="center" bgcolor="#7A7F89">编 号</td> <td width="200" align="center" bgcolor="#7A7F89">名称 </td> <td width="75" align="center" bgcolor="#7A7F89">颜 色</td> <td width="75" align="center" bgcolor="#7A7F89">尺 寸</td> <td width="75" align="center" bgcolor="#7A7F89">零售价</td> <td width="75" align="center" bgcolor="#7A7F89">会员价</td> <td width="75" align="center" bgcolor="#7A7F89">数 量</td> <td width="75" align="center" bgcolor="#7A7F89">商品金额</td> <td align="center" bgcolor="#7A7F89">操作</td> </tr> <% i=0 do while not rs.eof '查询单件商品信息 set prodrs=server.CreateObject("adodb.recordset") prodsql="select * from bproduc where ProdId='"&rs("ProdId")&"'" prodrs.open prodsql,conn,3,2 %> <tr> <td width="60" align="center"><%=prodrs("ProdId")%></td> <td width="200" align="center"><%=prodrs("ProdName")%></td> <td width="75" align="center"><%=myyansearr(i)%></td> <td width="75" align="center"><%=mychimaarr(i)%></td> <td width="75" align="center"><%=prodrs("PriceOrigin")%></td> <td width="75" align="center"> <%if UserType<>"" then huiyuanjia=CInt(prodrs("PriceOrigin")*(zhikou(UserType)/10)) else huiyuanjia=prodrs("PriceOrigin") end if %> <%=huiyuanjia%></td> <td width="75" align="center"><%=shuliangarr(i)%></td> <td width="75" align="center"><%jine=huiyuanjia*shuliangarr(i)%><%=jine%></td> <td align="center"><a href='javascript:if(confirm("你确定要删除该商品吗?"))location="?action=delshangpin&delid=<%=prodrs("ProdId")%>"'>删除</a></td> </tr> <% prodrs.close set prodrs=nothing i=i+1 zongjine=zongjine+jine rs.movenext loop %> </table> <table width="960" height="50" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td align="right" style="font-size:14px;">商品总金额:<span style="color:#CC0000; font-family:Arial; font-weight:bold; font-size:20px;">¥<%=zongjine%></span></td> </tr> </table> <table width="960" height="50" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td align="center"><input name="jxgw" type="button" id="jxgw" value="继续购物" onclick="window.location.href='cat.asp';" /> <input name="tjdd" type="button" id="tjdd" value="提交订单" onclick="<%if request.cookies("www3gushopcom")("userid")<>"" then%>window.location.href='dingdan.asp';<%else%>window.location.href='alogin.asp';<%end if%>" /> <input name="cleargouwuche" type="button" id="cleargouwuche" value="清空购物车" onclick="location='?action=cleargouwuche'" /></td> </tr> </table> </body> </html>