php购物车实现代码(1/2)_PHP教程

原创
2016-07-20 11:08:29 1199浏览

关于购物车,这个是在电子商务方面使用的比较多,用户选择好自己的商品需要保存起来,最后去收银台,这很像我们实际生活的超市,所以我现来写一个简单的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 "";
echo "";
echo "";
echo "";
echo "";
echo "";
}
echo "
产品编号产品名称单价剩余数量产品描述放入购物车
".$row_inventory->id."".$row_inventory->product."".$row_inventory->price."".$row_inventory->quantity."".$row_inventory->description."
";
echo "
购物车中产品的数量∶".$cart->quant_items($table, $session);
echo "

清空购物车";

1 2

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/444892.htmlTechArticle关于购物车,这个是在电子商务方面使用的比较多,用户选择好自己的商品需要保存起来,最后去收银台,这很像我们实际生活的超市,所...

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
上一条:PHP免费发送短信代码(利用中国移动飞信)(1/3)_PHP教程 下一条:php简单中文分词系统(1/2)_PHP教程

相关文章

查看更多