麻辣堂|资源主站|开发论坛|在线手册
首页 Apache Linux Java MySQL 注册帮助 
PHP项目开发组是PHP开发资源网于2007组年建成立的项目开发团队,目前核心开发成员有27人, 项目协作成员8名.下设7个开发组,主要承接大/中型网站项目开发任务。

    由于开发任务较多,人员比较紧张,现面向社会招聘全职或者兼职开发人员,不管你是在校大学生,还是全职开发人员,以及SOHO都可以联系本站,我们可以长期合作,并为您带来丰厚的报酬。
  您现在的位置:PHP开发资源网 > 麻辣堂 > 详细资料
待解决
在线急等: 哪位好心人帮我看看我的购物车为什么显示不出添加了的物品?多谢了!!
悬赏分:20 - 2007年08月14日

这是showproduct.php页: <? include "cart.php"; //包含购物车类的文件 .........通过数据库查找物品,按"放入购物车"按钮后,$job的值改为"addproduct".(这部分能正常显示,没问题,省略,关键是下面按"放入购物车"后,只能显示购物车,但里面没有刚添加的物品) //如果参数为添加商品,执行操作. if($job=="addproduct") { if(isset($cart)) { $cart->add_item($productid); } else { $cart=new cart; $cart->add_item($productid); <---------cart.php里显示添加商品的函数,$productid为商品号. $cart->showcart(); <---------cart.php里显示购物车的函数 } } ........... ?> 这是cart.php页有关添加商品,和显示购物车函数的部分: <? //本文件是购物车类的定义 class Cart { var $Cartitem; //此变量用来存放商品数据,实质是二维数组 var $count; //商品数量 var $owner; //用户id var $time; //时间 var $cartid; //购物车编号 //初始化结构函数 function Cart() { $this->count=0; if(isset($userid)) { $this->owner=$userid; } else { $this->owner=0; } $this->time=date("Y-m-d"); $this->cartid=time(); } //添加商品的函数 function add_item($productid) { //设定标志变量 $flag=FALSE; for($i=1;$i<=$this->count;$i++) { //检查在购物车里是否已有相同商品 //如果有的话,设定标志为真 //相应的的商品数量加一 if($this->cartitem[$i]["productid"]==$productid) { $this->cartitem[$i]["quantity"]++; $flag=TRUE; break; } } //如果标志变量为假,说明在购物车里没有相同的商品 //向购物车里面加入商品名,id,价格和数量. if($flag=FALSE) { session_register("cart"); $connect=mysql_connect("localhost","Wdwlbsm"); mysql_select_db("ebusiness"); $query="select productid,price,productname from product where productid='$productid'"; $result=mysql_query($query); $res=mysql_fetch_object($result); $price=$res->price; $productname=$res->productname; $productid=$res->productid; mysql_close($connect); $this->count++; $this->cartitem[$count]["productid"]=$productid; $this->cartitem[$count]["quantity"]=1; $this->cartitem[$count]["price"]=$price; $this->cartitem[$count]["productname"]=$productname; } } //显示购物车的函数. function showcart() { echo'

'; $total=0; for($i=1;$i<=$this->count;$i++) { echo''; echo''; echo''; $sum=$this->cartitem[$i]["quantity"]*$this->cartitem[$i]["price"]; echo''; echo''; echo''; } echo'
商品名 数量 价格 总计 删除
'.$this->cartitem[$i]["productname"].' '.$this->cartitem[$i]["price"].''.$sum.'cartitem[$i]["productid"].'>删除该物品
'; echo'

总金额为:'.$total.'元..

'; echo'

'; echo'
'; } } ?> 为什么它显示不出我添加了的商品呢?!

提问者:hthc   08-14 09:09
答复
路过。。。顺便帮顶:)
回答者:玉米づ冰冻可乐 - 瓦岗村民 8-22 09:10
我也来回答:
不管你有没有帮助我们,瓦岗寨8万村民将感谢你。。。。。

为防止灌水,您需要计算一道数学题: 答案:
48 + 21 = ? 请将计算结果填在上面

 
[]
©2007 PhpRes.COM