I'm writing a shopping basket which is working fine, except when I want to delete an item from the basket.
It's using an array to store three pieces of information for each position in the array (3 columns and variable rows). This is pulled out to a session then read back to a session when stored. It increases in size length as a product is added to the basket. When the product is added, a remove button is displayed allowing the user to click on it to remove that item (identified by PID). This works OK, but only if the products are deleted from the last item to the first. If I try it in any other order I get odd results
- sometimes it'll delete all the items but leave a remaining blank row, other times it'll delete only the ones with that PID but also in between them in the array.
How can I delete from the array at any position where the PID matches that inputted without affecting the other rows?
Here's my current remove function:
Any ideas woudl be great! Thanks!
It's using an array to store three pieces of information for each position in the array (3 columns and variable rows). This is pulled out to a session then read back to a session when stored. It increases in size length as a product is added to the basket. When the product is added, a remove button is displayed allowing the user to click on it to remove that item (identified by PID). This works OK, but only if the products are deleted from the last item to the first. If I try it in any other order I get odd results
- sometimes it'll delete all the items but leave a remaining blank row, other times it'll delete only the ones with that PID but also in between them in the array.
How can I delete from the array at any position where the PID matches that inputted without affecting the other rows?
Here's my current remove function:
Code:
Function DeleteFromBasket(PID)
basketArray = Session("basketArray")
basketMaxUsed = Session("basketMaxUsed")
Dim a 'Loop var
For a = 0 to UBound(basketArray,2)
If basketArray(0,a) = PID Then
basketMaxUsed = basketMaxUsed - 1 'Change max size
basketArray(0,a) = null
basketArray(1,a) = null
basketArray(2,a) = null
End If
Next
Redim Preserve basketArray(BASKET_COLUMNS,basketMaxUsed) 'Reduce array size
End Function
Any ideas woudl be great! Thanks!