蝙蝠岛资源网 Design By www.hbtsch.com
在wamp环境下,用PHP的session会话控制完成购物车的效果,数据存放在数组里练习,没有连接数据库,效果不错,简单易懂,以下是各部分的代码
common.php
<"content-type:text/html;charset=utf-8");
$arrPro = array(
array('id'=>1,'img'=>'img/1.jpg','title'=>'小米移动电源5000mAh','price'=>49),
array('id'=>2,'img'=>'img/2.jpg','title'=>'20000mAh小米移动电源2','price'=>149),
array('id'=>3,'img'=>'img/3.jpg','title'=>'小米圈铁耳机Pro','price'=>129),
array('id'=>4,'img'=>'img/4.jpg','title'=>'小米家电动滑板车','price'=>1999),
array('id'=>5,'img'=>'img/5.jpg','title'=>'小米笔记本','price'=>3499),
array('id'=>6,'img'=>'img/6.jpg','title'=>'米家LED智能台灯','price'=>169),
array('id'=>7,'img'=>'img/7.jpg','title'=>'小米体重秤','price'=>99),
array('id'=>8,'img'=>'img/8.png','title'=>'小米电视3s 48英寸','price'=>2599)
);
index.php
<"content-type:text/html;charset=utf-8");
require 'common.php';
session_start();
$sum = 0;
$class = "";
//判断左上角购物车的样式显示
if(!empty($_SESSION['shopcar'])){
$data = $_SESSION['shopcar'];
$sum = array_sum($data[4]);
$class = "on";
//右上角圆点
if(empty($data[0])){
$class = "";
}
}
"en">
<head>
<meta charset="UTF-8">
<title>商品展示</title>
<style type="text/css">
section{
width:1032px;
height: 700px;
margin: 40px auto;
}
.top{
float: right;
position: relative;
width: 190px;
height: 34px;
border: 1px solid #ccc;
margin-right: 32px;
text-align: center;
line-height: 34px;
border-radius: 4px;
transition: all .3s linear;
-moz-transition: all .3s linear;
-webkit-transition: all .3s linear;
}
.top a{
color: #d00;
}
.top:hover{
width: 210px;
color: #fff;
font-weight: bold;
background-color: #d00;
border-radius: 6px;
}
.top:hover a{
color: #fff;
}
.top:hover span{
background-color: #fff;
color: #d00;
}
.top:hover .star{
right:150px;
top: 0;
font-size: 14px;
color: #ff0;
transform: rotate(1080deg);
}
.top span{
position: absolute;
top:2px;
right: 40px;
width: 18px;
height: 18px;
font-weight: bold;
border-radius: 9px;
line-height: 18px;
text-align: center;
font-size: 12px;
font-weight: border;
color: #fff;
}
.star{
color: #fff;
font-size: 48px;
font-style: normal;
position: absolute;
right:530px;
top:186px;
transform: rotate(60deg);
transition: all .3s ease;
}
.on{
background-color: #e00;
}
.list{
margin: 20px 20px;
padding: 36px 0;
list-style: none;
}
a{
display: block;
color: #757575;
text-decoration: none;
}
.list li{
float: left;
height: 246px;
width: 234px;
padding: 10px 0 20px;
margin-right:12px;
margin-top: 20px;
border: 1px solid #ccc;
background: #fff;
-webkit-transition: all .2s linear;
transition: all .2s linear;
}
.list li:hover{
box-shadow: 2px 4px 5px #aaa;
}
.figure{
width: 150px;
height: 150px;
margin: 0 auto 18px;
}
.title{
color: #222;
font-size: 14px;
font-weight: normal;
text-align: center;
}
.price{
margin: 0 10px 10px;
text-align: center;
color: #ff6700;
}
.cart{
margin: 0 15px 5px;
text-align: center;
}
.cart a{
color: #a34;
width: 190px;
height: 24px;
border-radius: 4px;
margin: 0 8px 5px;
text-align: center;
}
.cart a:hover{
color: #eee;
box-shadow: 0 2px 1px #333,0 2px 1px #666;
background-color: #ccc;
background-image: linear-gradient(#33a6b8,#0089a7)
}
.num{
text-align: center;
color: #ff6700;
}
</style>
</head>
<body>
<section>
<div class='top'>
<a href="spcar.php" rel="external nofollow" >我的购物车</a><span class="<"><"list">
<"figure">
<a href=""><img src="/UploadFiles/2021-04-02/ rel=">
<"购物车没有商品!";
}
spcar.php
<"购物车没有商品!";
}
delete.php
<?php
session_start();
if(!empty($_GET['id'])){
$arrData = $_SESSION['shopcar'];
//判断对应的商品ID信息
if(in_array($_GET['id'],$arrData[0])){
unset($arrData[0][$_GET['id']]);
unset($arrData[1][$_GET['id']]);
unset($arrData[2][$_GET['id']]);
unset($arrData[3][$_GET['id']]);
unset($arrData[4][$_GET['id']]);
$_SESSION['shopcar'] = $arrData;
}
header('Location:spcar.php');
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
标签:
PHP,session,购物车
蝙蝠岛资源网 Design By www.hbtsch.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
蝙蝠岛资源网 Design By www.hbtsch.com
暂无PHP session实现购物车功能的评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
2025年11月06日
2025年11月06日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]