PHP4 session implementation of mini shopping basket Five _php tutorial

Source: Internet
Author: User
?。 Fill Basket
$#@60;? Php
$basket _position_counter=0; The position in the basket
$double = 0; Dual entry flag set to No
if ($ses _basket_items$#@62;0) {
Check if the basket contains a double entry in the project
foreach ($ses _basket_name as $basket _item) {
Iterate through the names contained in the array and check to see if the matches from the href
if ($basket _item== $basket) {
If you already have an item in the basket, set flag to 1
$double = 1;
Remember the location of the project and update it
$basket _position= $basket _position_counter;
}
$basket _position_counter++; Increase the actual position in the basket
}
}
Update Basket
if ($double ==1) {
If the item already exists in your basket, update the number and location of the $basket_position processing
$oldamount = $ses _basket_amount[$basket _position];
$ses _basket_amount[$basket _position]++;
$amount = $ses _basket_amount[$basket _position];
$oldprice = $ses _basket_price[$basket _position];
Update Price
$newprice = ($oldprice/$oldamount) * $AMOUNT;
$ses _basket_price[$basket _position]= $newprice;
}else{
If it's not in your basket, add a new item at the end of the array
$ses _basket_name[]= $basket;

$ses _basket_amount[]=1;
$ses _basket_price[]= $price;
$ses _basket_id[]= $id;
$ses _basket_items++;
}
? $#@62;
Great, now you can fill the mini shopping basket and show it.
Organize code Snippets together
Let's organize the code together and save it as a minibasket.inc.
$#@60;? Php
Remember that in code Snippet 1, the decision is not to increase?
Let's repeat it here.
if ($basket! = "") {
Here, the project will be added to the basket. Let's check if there's a registered basket.
if (session_is_registered ("Ses_basket_items")) {
There is a registered basket, put code snippet 4 here.
It adds items to the registered basket, checks for duplicate records, updates them or adds items at the end of the array
} else {
There is no registered basket, put code snippet 3 here. It creates a new basket, and
Register it through the session.
}
}
All that's left is code snippet 2. Used to display items in the basket if they are present.
Add to this.
? $#@62;
Look, it's good. "Cest tout," the French would say. If looser play Irresolute 4 Niao supper Xin raise 猰 inibasket.inc and include it in the display of the product PHP page.
Minibasket.inc and basket.php in zip format

http://www.bkjia.com/PHPjc/531762.html www.bkjia.com true http://www.bkjia.com/PHPjc/531762.html techarticle ?. Fill basket $#@60;? PHP $basket _position_counter=0; The position in the basket $double = 0; Double entry flag set to No if ($ses _basket_items$#@62;0) {//Check whether the basket contains items ...

  • 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.