Mini shopping basket 2 implemented by PHP4Session

Source: Internet
Author: User
You must know what session is. If you do not know, here is a quick outline. There are many articles about this topic, from which you can find all the code examples you need. Open a session on your start page and use $ # @ 60 ;? Phpsession_start ();? $ #@ 62; SyntaxHighligh

Requirements
You should know what session is. If you do not know, here is a quick outline. There are many articles about this topic, from which you can find all the code examples you need. Open a session on your start page and use $ # @ 60 ;? Php
Session_start ();
? $ #@ 62;
This creates a session name and a session id. Now you can use the default cookie-based session setting method to pass the session id through a form or attach it to your link as a variable (get method). Do not forget to release the session at the end. :)
Your product should have a name, price, and unique identifier so that it can be used in this example. if this is not the case, you may need to make some modifications. Here I use mysql as the backend to create pages and other things. it is not necessary to make shopping work. :)
You should understand arrays. Now, if someone has time to use my code and create a class for it, I naturally appreciate it.
Definition
To simplify this example, I used four independent arrays and some additional variables. Code can be optimized. This allows you to easily display ideas and read code. The class can be better done, but I am not sure whether the object can be saved to the session. Does anyone want to comment on this?
We also need a project counter. Of course, you can use the count () command to implement it. I just think it is good enough to always know how many items there are, and it also provides a good counter for the loop.
Work
Let's assume that there is a product list on your HTML page.
ID Name Price
1 Mouse 25.00 add
2 Key 100.00 add
3 Car 5000.00 add
4 Game 25.00 add

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.