In order to explain the convenience, the key point, this article uses the array realization to display the commodity information. But in the actual system development, the data of these commodity information should come from the backstage database.
In the program, we define an SP array and assign it a value, and then use a loop to implement its data display and data transfer to the next program. Part of the code for the program is as follows:
<% i=1
do while (i<=5) %>
<tr > <td><%=sp(i)%></td>
<td><a href=“cart.asp?spid=<%=sp(i)%>”>订购</a></td> </tr>
<% i=i+1
loop %>
Build a shopping Cart
To handle the user ordering items, we have customized two session properties, namely, "spid" (to hold the product name) and "Num" (to hold the order quantity of the corresponding product). When a user orders a product, we divide the session in three different situations:
Shopping cart is empty, that is, session ("spid") = "", directly to the SPID and NUM into session;
Shopping cart is not empty and the current order of goods is not in the shopping cart, the treatment method ibid;
Shopping cart is not empty but the current order of goods is the shopping cart already existing, the session remains unchanged.
The key point of the program implementation is how to determine if the current order is present in the shopping cart, so first you split the contents of the session variable into an array:
Array1=split (Session ("SPID"), ":"
The loop statement is then used to determine if there are elements in the array1 that are the same as the passed SPID and deposit the results in variable ifbuy:
for i=0 to ubound(array1)-1
if array1(i)= Request.QueryString(“spid”) then
ifbuy=true
exit for
end if
next
Add new product information to the session:
Session ("SPID") =session ("spid") & Request.
QueryString ("spid") & ":"
Another custom property num of the session object is treated like a spid.