请问购物车ASP源程序的一个错误,如何修正?+

来源:百度知道 编辑:UC知道 时间:2024/05/14 19:15:06
请问高手朋友们,以下代码能优化,解决本问题吗》?
以下是执行增加购物清单的ASP代码:
=====代码部分======
<%Sub PutToShopBag( cpbm, ProductList )
If Len(ProductList) = 0 Then
ProductList = "" & cpbm & ""
ElseIf InStr( ProductList, cpbm ) <= 0 Then
ProductList = ProductList & "," & cpbm & ""
End If
End Sub
ProductList = Session("ProductList")
Products = Split(Request("cpbm"), ",")
For I=0 To UBound(Products)
PutToShopBag Products(I), ProductList
Next
Session("ProductList") = ProductList
Head="以下是您所选择的产品清单"
ProductList = Session("ProductList")
If Len(ProductList) =0 Then
Response.Redirect "Product.asp"
response.end
end if
If Request("MySelf") = "Yes" Then
ProductList = ""
Products = Split(Request("cpbm"), ",")
For I=0 To U

你说的问题只要修改PutToShopBag过程就可以了。
你还有另外一个问题,原因和不能加入购物车的原因是一样的,就是,在你上面代码的最后一段,查询语句"Where ArticleId In (" & ProductList & ")"。比如,购物清单中有编号为15的产品,而该语句会把编号1、5、15的产品都选出来。
一般有两种方法,一,是使用数组,做一个循环比较,但是在查询语句中不好实现。要不然,就把数字编号用特殊字符括起来成为[n1][n2]...的序列。比如:
Sub PutToShopBag( cpbm, ProductList )
If Len(ProductList) = 0 Then
ProductList = "[" & cpbm & "]"
ElseIf InStr( ProductList, "[" & cpbm & "]") <= 0 Then
ProductList = ProductList & ",[" & cpbm & "]"
End If
End Sub

相应的,查询语句的条件子句应为:
" ... Where ('[' & ArticleId & ']') In (" & ProductList & ")"

" ... Where Instr(ProductList,'[' & ArticleId & "]')>0"