Home > Backend Development > PHP Tutorial > Mini Shopping Basket Three Implemented by PHP4 Session_PHP Tutorial

Mini Shopping Basket Three Implemented by PHP4 Session_PHP Tutorial

WBOY
Release: 2016-07-13 17:28:47
Original
848 people have browsed it

b>Add a link to your page
The add field above should be a link to add items to the mini shopping basket. Use $PHP_SELF to point this link to itself. Then add product information to it. Here is an example for item 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 put it at the end of the link. The Get method seems to be 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 include files. The reason for using this external file is that although you will be using session variables to pass to the basket, the code still needs to be valid. This file will contain the code to display the mini basket, as well as the function to add items. The best place to implement it is to $#@60;?php include ("minibasket.inc"); ?$#@62; Put the commands where you need them.
The logic of minibasket.inc
Take some time to think about this. What should a mini basket look like and what features does it need? The mini basket shown here should look like Like this:
# Name Price
1 Mouse 25.00
3 Game 75.00
Total 100.00
You can easily format this output by using an external stylesheet. However, it shouldn't be too complicated. Large. This mini-basket is a piece of information, however it should not be the focus of the page you are displaying. The logic of this file is very simple.
If true, add the item. It checks for duplicate records and updates existing records by updating the quantity and price.
Fragment 1. Checks for new items to be added. This is a normal IF statement used to check the value of the $basket variable.
$#@60;?php if ($basket!=""){//Add items to the basket} ?$#@62;
Fragment 2 Display the basket in the browser$#@60. ;?php if ($ses_basket_items$#@62;0){ // If there are items in the basket


for ($basket_counter=0;$basket_counter$#@60;$ses_basket_items;$basket_counter++){ // Traverse the basket and print out each row // Of course you can use a grid to format the display // You need to format to display the price points. If there is no formatting, .00 will not be 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 basket // Set item count to 0 and clear all variables // Is this a cleanup? It prevents people from getting the old array
$ses_basket_items=0;
unset($ses_basket_name);
unset($ses_basket_amount);
unset($ses_basket_price);
unset($ses_basket_id); }
?$#@62; This code will not produces no results. The items have not been filled yet, so the basket will not be displayed. So let's add some items to this basket.

http://www.bkjia.com/PHPjc/531749.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531749.htmlTechArticleb>Add a link to your page The add field above should be a link to put the product on the mini in shopping basket. Use $PHP_SELF to point this link to itself. Then add quotient to it...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template