发新话题
打印

请教 PHP购物车类

PHP购物车类 那里出错了

<?php                     //gouwu.php
session_start();
include "inc/config.php"; //连接数据库的文件
class cart
{
var $cartitem; //存放商品数据
var $count;      //商品种数量
var $product_count;    //商品数量
var $owner;     //用户ID
var $time;      //时间
var $orderid;    //购物车编
function cart()
{
        $this->count=0;
}
#--------------添加商品的函数------------------------#
function add_item($id)
{
    global $producttable;//数据库表
    $double=0;

    for ($i=0;$i<$this->count;$i++)
    {
            if($this->cartitem[$i]["id"]==$id)
            {
                    $this->cartitem[$i]["product_count"]++;
                    $double=1;
                    break;
       }
     }   

if ($double==0){
$sql="select productname,vip_price from $producttable where id=$id";
$sql_query=mysql_query($sql);
$row=mysql_fetch_object($sql_query);
$goodprice=$row->vip_price;
$pname=$row->productname;

$this->cartitem[$count]["id"]=$id;
$this->cartitem[$count]["product_count"]=1;
$this->cartitem[$count]["price"]=$goodprice;
$this->cartitem[$count]["productname"]=$pname;

}
}
#-----------显示购物车的函数------------------------------#
function showProduct()
{
        for($i=0;$i<$this->count;$i++)
        {

                         echo $this->count;
                         echo $this->cartitem[$i]["price"];  /*这个地方是显示空的,想问是那里出错了*/
                         echo $this->cartitem[$i]["productname"]; /*这个地方是显示空的,想问是那里出错了*/
                         echo "<br>";
        }
}
               
}
#-------------------------------------------#
if($act=="add")//我有个提交的连接如:<a href=gouwu.php?act=add&id=8>
{
    if(session_is_registered("cart"))
    {
            $cart->add_item($id);
    }
    else
    {         
    $cart=new cart();
          session_register("cart");
          $cart->add_item($id);
    }
    $cart->showProduct();
}

?>      

TOP

发新话题