b> Add 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 point this link to its own. Then add the 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 name of the product can contain spaces, so put it at the end of the link. The Get method seems to be very picky about this.
Prepare a mini shopping basket
For code reuse, let's create an extra 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 use the session variable to pass to the shopping basket, the code still needs to be valid. This file will contain the code that displays the mini shopping basket, as well as the function of adding items to the message. The best place to achieve it is to be $#@60; php include ("Minibasket.inc");? $#@62; Place your commands where you need them.
The logic of Minibasket.inc
Take some time to think about this. What should a mini shopping basket look like and 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 this output by using an external style sheet. However, it should not be too big. This mini shopping basket is a message, however it should not be the focus of the page you are displaying. The logic of this file is very simple. Check if you need to add a new project.
If true, add the item in the join, it checks the record for the re-weight, updates the existing record by updating the quantity and the price.
Fragment 1. Examine the new item that will be added, which is a normal if statement that checks the value of the $basket variable.
$#@60;? php if ($basket! = "") {//Add item to basket}? $#@62;
Fragment 2. Display the basket $#@60 in the browser; 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 baskets, print out each row//You can of course use the grid to format the display/ /need to format to show the price score. If it is not formatted, then. 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 basket//Set item count to 0, and clear all variables//This is a clear place? 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 item has not been filled and the basket is always empty, so the basket will not be displayed. So let's add some items to this basket.
http://www.bkjia.com/PHPjc/531749.html www.bkjia.com true http://www.bkjia.com/PHPjc/531749.html techarticle b> 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 point this link to its own. Then add the quotient to it ...