?。 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 ...