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