Hi,
I currently have a shopping basket which is fine for one item at a time. It loads fast enough. However I adapted the code so people can choose multiple items via tick box, these can sometimes number 10 or more at a time. It's very slow and can sometimes take 15 seconds to load, mostly people won't wait around that long.
I think the problem is that it's going through the database and adding each item to the session object which is making it slow, I can't seem to find a quick way around this unless I totally rewrote the basket which is actually an adaptation of someone else's.
Here's the code that adds the item to the session.
Any ideas on improving the speed would be most appreciated.
Thanks
########################################################
sub addToCart()
For counter = 1 To Request.Form("track").Count
'This gets each individual track that was sent from a form
track=Request.Form("track")(counter)
'if it's empty to nothing
If scartItem < maxCartItems Then
scartItem = scartItem + 1
End If
Session("cartItem") = scartItem
dim rs, sqlProductInfo
'get the details for each track id
sqlProductInfo="SELECT * table1 RIGHT JOIN table2"
sqlProductInfo=sqlProductInfo & " ON table1.ID=table2.ID"
sqlProductInfo=sqlProductInfo & " WHERE Table2.ID=" & track & ""
'open connection - returns dbc as Active connection
call openConn()
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sqlProductInfo, dbc, adOpenForwardOnly,adLockReadOnly,adCmdText
If Not rs.EOF Then
'add the track to the session cookie
arrCart(cProductid,scartItem) = track
arrCart(cProductCode,scartItem) = rs("ID")
arrCart(cProductname,scartItem) = rs("nameview")
arrCart(cdescription,scartItem)= rs("Name")
arrCart(cQuantity,scartItem) = CInt(quantity)
arrCart(cUnitPrice,scartItem) = rs("price")
arrCart(cPostageUK,scartItem) = "0"
'arrCart(cPostageworld,scartItem) = rs("cpostageworld")
Session("MyCart") = arrCart
End If
next
call closeConn()
end sub
I currently have a shopping basket which is fine for one item at a time. It loads fast enough. However I adapted the code so people can choose multiple items via tick box, these can sometimes number 10 or more at a time. It's very slow and can sometimes take 15 seconds to load, mostly people won't wait around that long.
I think the problem is that it's going through the database and adding each item to the session object which is making it slow, I can't seem to find a quick way around this unless I totally rewrote the basket which is actually an adaptation of someone else's.
Here's the code that adds the item to the session.
Any ideas on improving the speed would be most appreciated.
Thanks
########################################################
sub addToCart()
For counter = 1 To Request.Form("track").Count
'This gets each individual track that was sent from a form
track=Request.Form("track")(counter)
'if it's empty to nothing
If scartItem < maxCartItems Then
scartItem = scartItem + 1
End If
Session("cartItem") = scartItem
dim rs, sqlProductInfo
'get the details for each track id
sqlProductInfo="SELECT * table1 RIGHT JOIN table2"
sqlProductInfo=sqlProductInfo & " ON table1.ID=table2.ID"
sqlProductInfo=sqlProductInfo & " WHERE Table2.ID=" & track & ""
'open connection - returns dbc as Active connection
call openConn()
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sqlProductInfo, dbc, adOpenForwardOnly,adLockReadOnly,adCmdText
If Not rs.EOF Then
'add the track to the session cookie
arrCart(cProductid,scartItem) = track
arrCart(cProductCode,scartItem) = rs("ID")
arrCart(cProductname,scartItem) = rs("nameview")
arrCart(cdescription,scartItem)= rs("Name")
arrCart(cQuantity,scartItem) = CInt(quantity)
arrCart(cUnitPrice,scartItem) = rs("price")
arrCart(cPostageUK,scartItem) = "0"
'arrCart(cPostageworld,scartItem) = rs("cpostageworld")
Session("MyCart") = arrCart
End If
next
call closeConn()
end sub