购物车浏览商品界面代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link rel="stylesheet" href="888.css" type="text/css" />
<script>
function test()
{
if(!confirm('确认购买吗?'))
return false;
}
</script>
</head> <body>
<div id="banner"></div>
<div id="link">
<ul type="none">
<li><a href="888_ok.php">浏览图书</a></li>
<li><a href="shop888.php">查看购物车</a></li>
<li><a href="clearshop.php">清空购物车</a></li>
</ul>
</div>
<div id="show">
<table width="90%" align="center" border="" cellpadding="" cellspacing="">
<tr>
<td width="5%" valign="middle">
<td width="5%" align="center">id</td>
<td width="20%" align="center">书名</td>
<td width="10%" align="center">价格</td>
<td width="30%" align="center">出版日期</td>
<td width="10%" align="center">类型</td>
</tr> <?php
include_once("../conn/conn.php");
$sqlstr="select * from tb_demo01 order by id";
$result=mysql_query($sqlstr,$conn);
while($rows=mysql_fetch_array($result))
{
echo"<tr><td align='left' height='25'> ";
echo "<input type=checkbox name='chk[]' id='chk' value=".$rows[].">";
echo"</td>";
for($i=;$i<count($rows);$i++)
{
echo"<td align='center' height='25'>".$rows[$i]."</td>";
}
echo"<td><a href='addshop11.php?id={$rows[0]}' onclick='return test()'>加入购物车</a></td>"; } ?>
</div>
</body>
</html>

点击加入购物车按钮后进入此页面,获取id进行传值
<?php
session_start();//启动会话
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link rel="stylesheet" href="shop888.css" type="text/css" />
</head>
<body>
<div id="banner"></div>
<div id="link">
<ul type="none">
<li><h3>添加商品到购物车,返回到<a href="shop888.php">我的购物车</a></h3></li>
</ul>
</div>
<div id="show">
<?php
include_once("../conn/conn.php");
$sql="select * from tb_demo01 where id={$_GET['id']}";
$result=mysql_query($sql,$conn);
if(empty($result)||mysql_num_rows($result)==)
{
die("没有找到要购买的信息");
}
else
{
$shop=mysql_fetch_array($result);
}
$shop["num"]=; //添加一个数量的字段
//var_dump($shop);
//如果存在则实现数量的累加,如果不存在则不累加
if(isset($_SESSION["shoplist"][$shop['id']]))
{
//如果存在,数量++
$_SESSION["shoplist"][$shop['id']]['num']++;
}
else
//如果不存在
{
$_SESSION["shoplist"][$shop['id']]=$shop;
}
?>
</div>
</body>
</html>

购物车显示页面
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link rel="stylesheet" href="shop888.css" type="text/css" />
<html>
<head></head>
<body>
<div id="banner"></div>
<div id="link">
<ul type="none">
<li><h3>我的购物车,返回商城<a href="888_ok.php">继续购买</a></h3></li>
</ul>
</div>
<div id="show">
<table border="" width=% cellpadding="" cellspacing="">
<tr>
<th>id</th>
<th>书名</th>
<th>价格</th>
<th>数量</th>
<th>小计</th>
<th>日期</th>
<th>类型</th>
</tr>
<?php
$sum=;
if(isset($_SESSION["shoplist"]))
{
foreach($_SESSION["shoplist"] as $value)
{
echo"<tr>";
echo"<td>{$value[0]}</td>";
echo"<td>{$value[1]}</td>";
echo"<td>{$value[2]}</td>";
echo"<td>
<button onclick='window.location.href='updateshop.php?id=$value[]&num=-''>-</button>
{$value['num']}
<button onclick='window.location.href='updateshop.php?id=$value[]&num=''>+</button>
</td>";//数量
echo"<td>".$value[]*$value['num']."</td>";
echo"<td>{$value[3]}</td>";
echo"<td>{$value[4]}</td>";
echo"<td><a href='clearshop.php?id=$value[0]'>删除</a></td>";
echo"</tr>";
$sum+=$value[]*$value['num'];
}
}
?>
<tr>
<th>总计金额:</th>
<th colspan="" align="right"><?php echo $sum; ?></th>
<td></td>
</tr>
</table>
</div>
</body>
</html>

购物车清空页面
<?php
session_start();//启动会话
//清空session中的商品
if($_GET['id'])
{
unset($_SESSION["shoplist"][$_GET['id']]);
}
else
{
unset($_SESSION["shoplist"]);
}
//跳转到购物车界面
header("Location:shop888.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>清空购物车</title>
</head>
<body>
</body>
</html>

简单购物车的实现,session的使用的更多相关文章

  1. Session小案例-----简单购物车的使用

    Session小案例-----简单购物车的使用 同上篇一样,这里的处理请求和页面显示相同用的都是servlet. 功能实现例如以下: 1,显示站点的全部商品 2.用户点击购买后,可以记住用户选择的商品 ...

  2. java:Session(概述,三层架构实例(实现接口封装JDBC),Session实现简单购物车实例)

    1.Session概述: Session:在计算机中,尤其是在网络应用中,称为“会话控制”.Session 对象存储特定用户会话所需的属性及配置信息.这样,当用户在应用程序的 Web 页之间跳转时,存 ...

  3. 一个简单的C#获取Session、设置Session类文件

    一个简单的C#获取Session.设置Session类文件,本类主要实现大家最常用的两个功能: 1.GetSession(string name)根据session名获取session对象: 2.Se ...

  4. 简单购物车程序(Python)

    #简单购物车程序:money_all=0tag=Trueshop_car=[]shop_info={'apple':10,'tesla':100000,'mac':3000,'lenovo':3000 ...

  5. python实现简单购物车系统(练习)

    #!Anaconda/anaconda/python #coding: utf-8 #列表练习,实现简单购物车系统 product_lists = [('iphone',5000), ('comput ...

  6. Python实例---简单购物车Demo

    简单购物车Demo # version: python3.2.5 # author: 'FTL1012' # time: 2017/12/7 09:16 product_list = ( ['Java ...

  7. 用Python实现简单购物车

    作业二:简单购物车# 实现打印商品详细信息,用户输入商品名和购买个数,则将商品名,价格,购买个数加入购物列表,# 如果输入为空或其他非法输入则要求用户重新输入 shopping_list = [] w ...

  8. Session 简单购物车

    package session.test; import java.io.IOException; import java.io.PrintWriter; import java.util.Linke ...

  9. 2017.9.28 web设计简单的购物车应用案例--session的简单应用

    该购物过程是在session范围内完成的,需要使用session对象实现信息的共享 (1)购买“肉类”商品的页面 <%@ page language="java" impor ...

随机推荐

  1. Sublime Less 自动编译成css

    1.note编译 .下载notejs https://nodejs.org/en/ .首先你要安装lessc.我是用npm包管理器直接安装的,只需要一条命令,如下: npm install less ...

  2. chkconfig --add失败的处理方法

    author: headsen  chen datet:2018-08-30   11:57:49 1,在/etc/init.d/下面添加两个文件,并授予 +X 的权限,效果如下: 2,添加到开启自启 ...

  3. 【BZOJ4196】[Noi2015]软件包管理器 树链剖分

    [Noi2015]软件包管理器 树链剖分 Description Linux用户和OSX用户一定对软件包管理器不会陌生.通过软件包管理器,你可以通过一行命令安装某一个软件包,然后软件包管理器会帮助你从 ...

  4. Yii2框架添加API Modules

    原文链接:http://www.itnose.net/detail/6459353.html : 一.环境部署 1. read fucking Yii Documents. http://www.yi ...

  5. 03Del.ashx(删除班级)

    03Del.ashx 数据库里定义个BOOL型,TRUE表示正常FALSE表示删除 using System; using System.Collections.Generic; using Syst ...

  6. ZOJ 3203 Light Bulb

    Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow a ...

  7. windows 文件查找 大小:>250M

    win7怎么快速查找大文件_百度经验 https://jingyan.baidu.com/article/acf728fd299ffff8e510a333.html

  8. android 获取经纬度

    android 定位的两种方式:GPS_PROVIDER and NETWORK_PROVIDER 定位的可以借助LocationManager来实现 MainActivity代码 static fi ...

  9. Java-小技巧-003-static、final、static final的区别

    final可以修饰:属性,方法,类,局部变量(方法中的变量) final修饰的属性的初始化可以在编译期,也可以在运行期,初始化后不能被改变,jvm会将其分配到常量池中,程序不可改变其值: final修 ...

  10. hive两大表关联优化试验

    呼叫结果(call_result)与销售历史(sale_history)的join优化: CALL_RESULT: 32亿条/444G SALE_HISTORY:17亿条/439G 原逻辑 Map: ...