网络编程
位置:首页>> 网络编程>> Asp编程>> 一个asp简单购物车教程(3)

一个asp简单购物车教程(3)

  发布时间:2007-09-17 11:02:00 

标签:购物车,asp

其中最前面代码,下面的理解是我自已想的有可能有错,不过程序绝对没有错


:<% 
if not IsObject(session("cart")) then 
Set session("cart")=CreateObject("Scripting.Dictionary")’建立二维数组 
end if 
Set cart=session("cart")  
productID=Cstr(request("productID"))’定义变量productid为产品页传递过来的值 
dim detail(1) 
detail(0)=Int(request("quantity")) 
if request("productID")<>"" then 
if cart.Exists(productID) then 
cart.Remove(productID) 
end if 
cart.add productID,detail ’上面这一段我看不太懂,谁知道告诉我一下,不过和下面的有关 
end if 
keys=cart.keys ’定义变量KEYS的值为数组里面的产品ID 
items=cart.items ’定义变量items的值为数组里面的产品数量 
set session("cart")=cart  
%> 


代码二:


<% For i = 0 To cart.Count -1 %> ’设置多个产品的循环,cart.count是指购买几个产品,后面要以next结束 
<% Dim list__MMColParam 
list__MMColParam = keys(i) %> ’定义ID为cart数组里面的产品ID号 
<% set list = Server.CreateObject("ADODB.Recordset") 
list.ActiveConnection = MM_conn_STRING 
list.Source = "SELECT * FROM pro_table WHERE id = " + Replace(list__MMColParam, "’", "’’") + "" 
list.CursorType = 0 
list.CursorLocation = 2 
list.LockType = 3 
list.Open() 
%> ’上面的代码就不用我说了,其中要注意的:list__MMColParam = keys(i)  
………………………………………… <% 
list.Close() 
%> 
<% next %> 



 
取消订购的产品:delcart.asp


<% 
Set cart=session("cart") 
if request("productID")<>"" then 
productID=Cstr(request("productID")) 
cart.Remove(productID) 
end if 
set session("cart")=cart 
response.redirect("cart.asp") 
%> 



order.asp源码,这里很简单,看一下就明白了


<HTML><HEAD> 
<TITLE>浙江广源印刷包装有限公司</TITLE> 
<META http-equiv=Content-Type content="text/html; charset=gb2312"> 
<LINK  
href="index/index.css" type=text/css rel=stylesheet> 
<META content="MSHTML 5.50.4807.2300" name=GENERATOR> 
</HEAD> 
<BODY text=#000000 bgColor=#ffffff leftMargin=0 topMargin=0 marginwidth="0" marginheight="0"> 
<div align="center">  
<form name="form2" method="post" action="sendorder.asp" onSubmit="return check1()"> 
<table width="514" border="0" cellspacing="0" cellpadding="0" height="15" align="center"> 
<tr>  
<td height="6" bgcolor="#FF9900"> <font color="#FFFFFF" size="2"> 购买者联系信息:</font></td> 
</tr> 
</table> 
<table border="0" cellspacing="0" cellpadding="0" align="center"> 
<tr>  
<td>  
<div align="center"><font size="2">联系人</font></div> 
</td> 
<td>  
<div align="left"><font size="2">  
<input type="text" name="n_ame" size="20"> 
</font></div> 
</td> 
</tr> 
<tr>  
<td>  
<div align="center"><font size="2">公司电话</font></div> 
</td> 
<td>  
<div align="left"><font size="2">  
<input type="text" name="t_el" size="20"> 
</font></div> 
</td> 
</tr> 
<tr>  
<td>  
<div align="center"><font size="2">电子邮箱</font></div> 
</td> 
<td>  
<div align="left"><font size="2">  
<input type="text" name="e_mail" size="20"> 
</font></div> 
</td> 
</tr> 
<td>  
<div align="center"></div> 
</td> 
<td> </td> 
</tr> 
</table> 
<p align="center">  
<input name="submit" type="submit" value="提交"> 
     
<input name="reset" type="reset" value="清除"> 
</p> 
</form> 
</div> 
</BODY></HTML> 


0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com