關於購物車,這個是在電子商務方面使用的比較多,使用者選擇好自己的商品需要儲存起來,最後去收銀台,這很像我們實際生活的超市,所以我現來寫一個簡單的php購物車執行個體代碼,比較詳細只要一步步,處理好就OK了。
php教程購物車實現代碼
關於購物車,這個是在電子商務方面使用的比較多,使用者選擇好自己的商品需要儲存起來,最後去收銀台,這很像我們實際生活的超市,所以我現來寫一個簡單的php購物車執行個體代碼,比較詳細只要一步步,處理好就ok了。
些購物車會用到php檔案
main.php 顯示商品
additem.php把商品加入購物車
cearcart.php刪除購物車中的商品
shoppingcart.php 操作類
使用者的資料庫教程有
inventory
create table inventory (
product tinytext not null,
quantity tinytext not null,
id int(4) default '0' not null auto_increment,
description tinytext not null,
price float(10,2) default '0.00' not null,
category char(1) default '' not null,
key id (id),
primary key (id),
key price (price)
);
insert into inventory values ('硬碟','5','1','80g','5600','1');
insert into inventory values ('cpu','12','2','p4-2.4g','6600','1');
insert into inventory values ('dvd-rom','7','3','12x','2000','1');
insert into inventory values ('主板www.bkjia.com','3','4','asus','5000','2');
insert into inventory values ('顯示卡','6','5','64m','4500','1');
insert into inventory values ('燒錄機','4','6','52w','3000','1');
shopping
create table shopping (
session tinytext not null,
product tinytext not null,
quantity tinytext not null,
card tinytext not null,
id int(4) default '0' not null auto_increment,
key id (id),
primary key (id)
);
shopper
create database shopper;
use shopper;
create table shopping (
session tinytext not null,
product tinytext not null,
quantity tinytext not null,
card tinytext not null,
id int(4) default '0' not null auto_increment,
key id (id),
primary key (id)
);
create table inventory (
product tinytext not null,
quantity tinytext not null,
id int(4) default '0' not null auto_increment,
description tinytext not null,
price float(10,2) default '0.00' not null,
category char(1) default '' not null,
key id (id),
primary key (id),
key price (price)
);
insert into inventory values ('硬碟','5','1','80g','5600','1');
insert into inventory values ('cpu','12','2','p4-2.4g','6600','1');
insert into inventory values ('dvd-rom','7','3','12x','2000','1');
insert into inventory values ('主板php100.com','3','4','asus','5000','2');
insert into inventory values ('顯示卡','6','5','64m','4500','1');
insert into inventory values ('燒錄機','4','6','52w','3000','1');
*/
//main.php 顯示購物車所有商品
include("shoppingcart.php");
$cart = new cart;
$table="shopping";
/* 查詢並顯示所有存貨表中的資訊 */
$query = "select * from inventory";
$invresult = mysql教程_query($query);
if (!($invresult)) {
echo "查詢失敗
";
exit;
}
echo "以下產品可供訂購∶";
echo "
"; echo "
| 產品編號 |
產品名稱 |
單價 | "; echo "
剩餘數量 |
產品描述 |
放入購物車 |
"; while($row_inventory = mysql_fetch_object($invresult)) { echo "
| ".$row_inventory->id." | "; echo "
".$row_inventory->product." | "; echo "
".$row_inventory->price." | "; echo "
".$row_inventory->quantity." | "; echo "
".$row_inventory->description." | "; echo "
product."'> |
"; } echo "
";
echo "
購物車中產品的數量∶".$cart->quant_items($table, $session);
echo "
清空購物車";
1 2
http://www.bkjia.com/PHPjc/444892.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/444892.htmlTechArticle關於購物車,這個是在電子商務方面使用的比較多,使用者選擇好自己的商品需要儲存起來,最後去收銀台,這很像我們實際生活的超市,所...