最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php购物车实现代码
时间:2010-07-17 编辑:简简单单 来源:一聚教程网
些购物车会用到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.111com.net','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 ('主板111com.net','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"); /* 查询并显示所有存货表中的信息 */ echo " 购物车中产品的数量∶".$cart->quant_items($table, $session); echo " 清空购物车"; |
代码如下 | 复制代码 | ||||||||||||
include("shoppingcart.php"); //clearcart.php删除商品,清除购物车代码 include("shoppingcart.php"); // shoppingcart.php类 /* 检查是否有 seesion, 如果没有产生一个 md5 的唯一 id, 并利用 cookie 存入 $s 中。
/* 购物车 class */ function add_item($table, $session, $product, $quantity) {
$total = $this->cart_total($table, $session); $contents["final"] = $total; return $contents; } function num_items($table, $session) { $query = "select * from $table where session='$session' "; $result = mysql_query($query); $num_rows = mysql_num_rows($result); return $num_rows; } function quant_items($table, $session) { $quant = 0; $query = "select * from $table where session='$session' "; $result = mysql_query($query); while($row = mysql_fetch_object($result)) { $quant += $row->quantity; } return $quant; } } |
?>
相关文章
- PHP实现添加购物车功能 05-26
- php购物车代码 06-02
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31
- Laravel实现登录跳转功能解析 10-31
- php双向队列解读 10-31