当前位置:首页 » 网购平台 » php通用购物车
扩展阅读
宁波奥德赛优惠价格 2021-03-15 14:26:02
丹尼斯购物卡能挂失么 2021-03-15 14:25:58
淘宝购物指纹验证失败 2021-03-15 14:24:44

php通用购物车

发布时间: 2021-02-05 12:46:08

⑴ php中购物车所有商品总价和。。。怎么弄

得到结果数组后
数组内加个字段比如 amount 值等于$row['goods_yuan']*$row['goods_num']
sum($row['amount'])

⑵ 一个最简单的用PHP实现购物车功能,请高手指点

这个感觉用cookie就好了啦
你一步步的跟踪一下,看看是哪儿没拿到值,可以在foreach之前把session的数组转存到一个变量里

⑶ php 购物车代码~呢

<?php 
class Shopcar 

//商品列表 
public $proctList=array(); 
/** 

* @param unknown_type $proct 传进来的商品 
* @return true 购物车里面没有该商品 
*/ 
public function checkProct($proct) 

for($i=0;$i<count($this->proctList);$i++ ) 

if($this->proctList[$i]['name']==$proct['name']) 
return $i; 

return -1; 

//添加到购物车 
public function add($proct) 

$i=$this->checkProct($proct); 
if($i==-1) 
array_push($this->proctList,$proct); 
else 
$this->proctList[$i]['num']+=$proct['num']; 

//删除 
public function delete($proct) 

$i=$this->checkProct($proct); 
if($i!=-1) 
array_splice($this->proctList,$i,1); 

//返回所有的商品的信息 
public function show() 

return $this->proctList; 


你可以去后盾人平台看看,里面的东西不错

⑷ 我用PHP做的购物车,为什么每次往购物车中添加不同商品 ,购物车中确显示的同一件商品啊

这个需要看你的购物车结构。
一般一个属性的商品是在一条数据里面,多次加入只是更改数量
不同属性的商品应该分多条数据保存。最后购物车统计的是总的数量

⑸ php 购物车。 在一产品列表上,任选多个产品,然后直接提交到购物车上。请问这个代码如何写,需要具体代码

可以用数组提交
表单中 这么写 <input name="a[]" type="checkbox" /> <input name="id[]" type="hidden" /><input name="num[]" />
关键是name=" "写成数组,具体写法看你的具体情况
后台回
//循环处答理 产品信息

foreach($a as $k => $v)
{
$now_id = $_POST['id'][$k];
$now_num = $_POST['num'][$k];
//下面你自己写

}

⑹ 跪求 PHP+Mysql实现购物车功能

PHP+Mysql实现购物车功能1.服务器端编程语言是需要购物车代码的,没有服务器代码阐述!

⑺ PHP怎么做购物车

<p>下载个ecshop参考一下吧,各方面的功能都齐了(当然包括了购版物车功能)。下载网址是:权 <a href="http://wenwen.soso.com/z/urlalertpage.e?sp=shttp%3a%2f%2fwww.ecshop.com%2fdownload.php" target="_blank">http://www.ecshop.com/download.php</a></p>

⑻ 【高分】急求用php写的购物车代码!!!!!(十万火急)如果您提供的好用还有加分!!!

我也要弄一个这种购物车,
我去写个,贴出来,【嘿嘿,今天上午新写的】。
我懒得新建数据库,用的是我的数据库。
你按照我的改一下就能用了
本人水平有限,高手请指正。
你,大,爷的,虽然不咋地,保证能用
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
经过调试,
//$my->add_cart(45,3,"茶几系列");//新增购物
//$my->updata_cart(13,13,8); //更新购物
//$my->del_cart(12,5,'Guest'); //删除一种购物
//$my->empty_cart('Guest'); //清空购物车
$ok=$my->get_cart('Guest'); //返回购物车
这些都可用
-------------------------------------------------------------------
<?php

class Cart
{

public $totalCost=0; //商品总金额

function cart($host,$usr,$pwd,$db)
{
mysql_connect($host,$usr,$pwd) or die(mysql_error);
mysql_select_db($db) or die(mysql_error);
mysql_query("SET Names GBk");
//只要有人访问,就自动清除一天前所有没付款的订单;
$sql="delete FROM shopcart WHERE TO_DAYS( NOW( )) - TO_DAYS( ptime ) >=1 and payment=0";
mysql_query($sql);

}

// 弹出提示
function alter($Str,$Url)
{
echo "<Script language='JavaScript'> alert('".$Str."');</Script>";
echo "<meta http-equiv=refresh content=0;URL=".$Url.">";
}

//增加购物;三个参数:pid:产品ID,ptl:产品数量,pcid:产品类别
//查询数据库,是否存在此人在本日内订过本产品
//如果订过,那么数量累加,否则插入一个数据库行
function add_cart($pid,$ptl=1,$pcid)
{
if($ptl>=100 || $ptl<=0)
{
$this->alter("最多买99件,最少1件","index.php");
die();
}

if(!$_SESSION['usr']) { $usr='Guest';}
else { $usr=$_SESSION['usr'];}

$sql="select * from shopcart where pid='".$pid."' and usr='".$usr."' and pcid='".$pcid."'";
$ex=mysql_query($sql);
$ex1=mysql_fetch_array($ex);

if(!$ex1)
{
$sql="select * from proct where ID='".$pid."' and class1='".$pcid."'";
$ok=mysql_query($sql);
$rs=mysql_fetch_array($ok);

if($rs)
{
$totalCost= $rs['Price'] * $ptl;

$sql="insert into shopcart(usr,pid,pname,ptl,price,pcid,psum,payment) Values(";
$sql.="'".$usr."',";
$sql.="'".$rs['ID']."',";
$sql.="'".$rs['Name']."',";
$sql.="'".$ptl."',";
$sql.="'".$rs['Price']."',";
$sql.="'".$rs['Class1']."',";
$sql.="'".$totalCost."',";
$sql.="'0')";

mysql_query($sql) or die(mysql_error());
if($ok) { $this->alter("购物成功","index.php"); }
else { $this->alter("购物失败","index.php"); }

}
else
{
$this->alter("不存在的商品,或者参数错误","index.php");
die();
}
}
else
{
$sql="update shopcart set ptl= ptl+1,psum = psum+price where ID='".$ex1['ID']."'";
mysql_query($sql);
$this->alter("更新数量成功","index.php");
}

}

//更新购物车的单个产品的数量;
function updata_cart($cid,$ptl,$pid)
{
if($ptl>=100||$ptl<=0)
{
$this->alter('产品数量不对!','index.php');
die();
}
$sql="select * from shopcart where ID='".$cid."' and pid='".$pid."'";
$ok=mysql_query($sql);
if(!ok) { alter("参数发生错误","index.php");}
else
{
$sql="update shopcart set ptl='".$ptl."',psum=price * '".$ptl."' where ID='".$cid."' and pid='".$pid."'";
$ok=mysql_query($sql);
if(!ok) { $this->alter("更新失败","index.php");}
else { $this->alter("更新成功","index.php");}
}
}
function del_cart($cid,$pid,$usr)
{
$sql="delete from shopcart where usr='".$usr."' and ID='".$cid."' and pid='".$pid."'";
$ok=mysql_query($sql);
if(!$ok) {$this->alter("删除失败","index.php");}
else {$this->alter("删除成功","index.php");}
}

function empty_cart($usr)
{
$sql="delete from shopcart where usr='".$usr."'";
mysql_query($sql) or die(mysql_error);
}

function get_cart($usr)
{
$sql="select * from shopcart where usr='".$usr."'";
$ok=mysql_query($sql);
return $ok;
}

}
$my = new Cart("localhost","root","root","mybbs");
//$my->add_cart(45,3,"茶几系列");
//$my->updata_cart(13,13,8);
//$my->del_cart(12,5,'Guest');
//$my->empty_cart('Guest');
$ok=$my->get_cart('Admin');

echo "usr pid pname ptl price pcid psum payment ptime <br><hr><br>";
while($rs=mysql_fetch_array($ok))
{
echo $rs[1]."->".$rs[2]."->".$rs[3]."->".$rs[4]."->".$rs[5]."->".$rs[6]."->".$rs[7]."->".$rs[8]."->".$rs[9]."<br>";

}

?>

、、、、、、、、、、、、、、、、、SQL、、、、、、、、、、、、、、

CREATE TABLE IF NOT EXISTS `shopcart` (
`ID` int(10) NOT NULL auto_increment,
`usr` varchar(50) NOT NULL,
`pid` int(5) NOT NULL,
`pname` varchar(100) NOT NULL,
`ptl` int(3) NOT NULL,
`price` decimal(50,2) NOT NULL default '0.00',
`pcid` varchar(100) NOT NULL,
`psum` decimal(50,2) NOT NULL default '0.00',
`payment` tinyint(1) NOT NULL,
`ptime` timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`)
)

proct 里面用的ID CLASS1是

`ID` int(6) NOT NULL auto_increment,
`Class1` varchar(20) NOT NULL,
`Price` int(6) NOT NULL,

⑼ 如何用html php制作购物车

网上有好多教程你随便搜一下就有了

⑽ 求php增加购物车数量的加减,

伪代码:
前端:在你页面上数量那栏增加

<div class="quantity-form"><a href="javascript:void(0);" clstag="cart_num_down" class="decrement disabled" id="decrement_8888_526830_1_1">-</a>
<input autocomplete="off" type="text" class="itxt" value="1" id="changeQuantity_8888_526830_1_1_0" minnum="1">
<a href="javascript:void(0);" clstag="cart_num_up" class="increment" id="increment_8888_526830_1_1_0">+</a>
</div>
你的购物车是个循环列表,可以去得到,每个商品的信息:id是商品
function cart_num_up(id,uid){
$.ajax({
type: "POST",
url: "CART_num.PHP",
data: {id:id, num:-1,uid:uid},
dataType: "json",
success: function(data){
if(data.status==1){

});
});

}
function cart_num_down(id,uid){
$.ajax({
type: "POST",
url: "CART_num.PHP",
data: {id:id, num:1,uid:uid},
dataType: "json",
success: function(data){
if(data.status==1){

});
});
}
点一次 加或减按钮,触发js向后端发起ajax请求:返回的是增加成功和失败状态和剩余数量;
CART_num.PHP
$id = (int)$_POST['id'];
$num = (int)$_POST['num'];
$uid =(int)$_POST['uid']; //有封装获取post或get函数更好
//查库看库存
$sort = get_kucun_num();
//查看购物车目前数量
$cart_num = get_cart_num(uid,id);
//判断库存
if($sort >$cart_num){
}else{
}

if($num<0){
//减法 $sql =“update cart set cart_num = cart_num-1 where uid =uid and id =id ”
if(($cart_num-1)>1){
}else{
}){
//加法 $sql =“update cart set cart_num = cart_num+1 where uid =uid and id =id ”
}else{
//不正确的请求
}