最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php购物车实例
时间:2010-08-16 编辑:简简单单 来源:一聚教程网
inventory表
代码如下 | 复制代码 |
create table inventory ( shoping表 create table shopping ( shoper表 create database shopper; |
代码如下 | 复制代码 |
/*mysql教程 --user=root --password=your_password */
/* 查询并显示所有存货表中的信息 */ echo " 购物车中产品的数量∶".$cart->quant_items($table, $session); echo " 清空购物车"; //shoppingcart.php代码 if (!$session && !$s) { $s = md5(uniqid(rand())); setcookie("session", "$s", time() + 14400); } /* 检查是否有 seesion, 如果没有产生一个 md5 的唯一 id, 并利用 cookie 存入 $s 中。
|
代码如下 | 复制代码 |
class cart { function add_item($table, $session, $product, $quantity) { |
代码如下 | 复制代码 | ||||||||||||
function display_contents($table, $session) {
$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; } } |
代码如下 | 复制代码 |
include("shoppingcart.php"); |
//清空购物车
代码如下 | 复制代码 |
include("shoppingcart.php"); |
-
上一个: php读取excel并查询指定数据
-
下一个: php批量重命名文件名
相关文章
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31
- Laravel实现登录跳转功能解析 10-31
- php双向队列解读 10-31
- Laravel异常上下文解决教程 10-24
- php数组查询元素位置方法介绍 10-24