Implement shopping cart in ASP

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.