PHP _ PHP Tutorial on mini shopping basket implemented by PHP4Session

Source: Internet
Author: User
The mini shopping basket 3 implemented by PHP4Session. B adds a link to your page. the add field above the link should be a link to put the product in the mini shopping basket. Use $ PHP_SELF to direct the link to itself. Then add Business B> link to your page
The add field above should be a link to place the item in the mini shopping basket. Use $ PHP_SELF to direct the link to itself. Then add product information to it. Here is an example of commodity 1.
$ #@ 60; a href = DownloadFilesa2000-09-08 $ # @ 60; $ echo $ PHP_SELF ;? $ # @ 62 ;? Id = 1 & price = 25 & basket = Mouse "$ # @ 62; add $ # @ 60;/A $ # @ 62;
The product name can contain spaces, so it is placed at the end of the link. The Get method seems very picky about this.
Prepare a mini shopping basket
For code reuse, let's create an additional file minibasket. inc. I use the. inc extension to identify my included files. The reason for using this external file is that the code still needs to be valid even if you pass the session variable to the shopping basket. This file contains the code for displaying the mini shopping basket, and adds the project function in the package. The best way to implement it is to set $ #@ 60 ;? Php include ("minibasket. inc ");? $ # @ 62; place the command where you need it.
Minibasket. inc logic
Take some time to consider this. What should a mini shopping basket look like? what features does it need? The mini shopping basket shown here should look like this:
# Name Price
1 Mouse 25.00
3. Game 75.00
Total 100.00
You can easily format the output by using an external style sheet. However, it should not be too large. This mini shopping basket is a piece of information, but it should not be the focus of your displayed page. The logic of this file is very simple. Check whether a new project needs to be added.
If this parameter is set to true, add a project to join the project. check the record with duplicate values and update the existing record by updating the quantity and price.
Segment 1. Check the new project to be added. this is a normal IF statement used to check the value of the $ basket variable.
$ #@ 60 ;? Php if ($ basket! = "") {// Add a project to the basket }? $ #@ 62;
Segment 2. Display the basket $ # @ 60; in the browser ;? Php if ($ ses_basket_items $ # @ 62; 0) {// if there is a project in the basket

For ($ basket_counter = 0; $ basket_counter $ # @ 60; $ ses_basket_items; $ basket_counter ++) {// traverse the basket, print each row // you can use a grid table to format the display // you need to format the price score. If not formatted,. 00 is not displayed.
$ Price = sprintf ("% 01.2f", $ ses_basket_price [$ basket_counter]);
$ Amount = $ ses_basket_amount [$ basket_counter];
$ Name = $ ses_basket_name [$ basket_counter];
Echo "$ amount $ name $ price ";
Echo "$ # @ 60; BR $ # @ 62;" ;}} else {// no items in the basket // set the project count to 0, and clear all the variables. // Is this a clearance? It prevents people from getting old arrays.
$ Ses_basket_items = 0;
Unset ($ ses_basket_name );
Unset ($ ses_basket_amount );
Unset ($ ses_basket_price );
Unset ($ ses_basket_id );}
? $ #@ 62; this code does not produce any results. The project has not been filled, and the basket is always empty, so the basket will not be displayed. So let's add some projects to this basket.

Http://www.bkjia.com/PHPjc/531749.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/531749.htmlTechArticleb> adding a link to your page the add field above should be a link to put the item in the mini basket. Use $ PHP_SELF to direct the link to itself. Then add a vendor to it...

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.