![]() |
|
首页 │ Apache │ Linux│ Java│ MySQL│ 注册│帮助 | |||
高手来看看,怎么判断这个变量传没传到下页呢?
showproduct.php:
<?
include "cart.php"; //包含购物车类的文件
$cart=new cart;
$cart->add_item($productid); <--------就是这个变量!!!!!!
?>
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)
{
if($this->count=0)
{
session_register("$cart");
}
//设定标志变量
$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")
{
$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;
}
}
?>
我用什么办法能判断showproduct.php里的$productid变量传到了cart.php里呢?多谢!!

