??. Fill the basket $ # @ 60 ;? Php $ basket_position_counter0; // the position in the basket $ double0; // Set the double entry flag to NOif ($ ses_basket_items $ # @ 62; 0) {// check whether the basket contains a dual entry foreach ($ ses_basket_nameas $ basket_item)
??. Fill basket
$ #@ 60 ;? Php
$ Basket_position_counter = 0; // the position in the basket.
$ Double = 0; // double entry flag is set to NO
If ($ ses_basket_items $ # @ 62; 0 ){
// Check whether the basket contains a double entry in the project
Foreach ($ ses_basket_name as $ basket_item ){
// Retrieve the name of the array and check whether it matches the name transmitted from href.
If ($ basket_item = $ basket ){
// If a project already exists in the basket, set flag to 1
$ Double = 1;
// Remember the project location and update it.
$ Basket_position = $ basket_position_counter;
}
$ Basket_position_counter ++; // add the actual position in the basket
}
}
// Update the basket
If ($ double = 1 ){
// If the project already exists in your basket, update the number and position of processing in $ basket_position.
$ Oldamount = $ ses_basket_amount [$ basket_position];
$ Ses_basket_amount [$ basket_position] ++;
$ Amount = $ ses_basket_amount [$ basket_position];
$ Oldprice = $ ses_basket_price [$ basket_position];
// Update the price
$ Newprice = ($ oldprice/$ oldamount) * $ amount;
$ Ses_basket_price [$ basket_position] = $ newprice;
} Else {
// If it is not in your basket, add a new project 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 in the mini shopping basket and display it.
Organize code snippets together
Let's organize the code together and save it as minibasket. inc.
$ #@ 60 ;? Php
// Remember, in code snippet 1, decide whether to add?
// Let's repeat it here
If ($ basket! = ""){
// Here, the project will be added to the basket. Let's check whether a registered basket exists.
If (session_is_registered ("ses_basket_items ")){
// There is a registered basket where code snippet 4 is stored.
// It adds a project to the registered basket, checks duplicate records, updates them, or adds a project at the end of the array
} Else {
// No registered basket exists. put code snippet 3 here. It creates a new basket and
// Register it through session.
}
}
// The rest are code snippet 2. Displays items in a basket.
// Add it here.
? $ #@ 62;
Look, good. "Cest tout", the French will say so. What if you're not playing? Why should I raise a four-member hacker ?? Inibasket. inc and include it in the PHP page that shows the product.
Minibasket. inc and basket. php in Zip format