<?

//error_reporting(0);

include("global.php");

$page=intval($_GET["pageid"]);

$id=intval($_GET["bigclassid"]);

$pagesize=9;

if($page=="" || $page==null)
{
	$page=1;
}
$offset=($page-1)*$pagesize;

if($offset<=0)
{
	$offset=0;
}

//判断是否是分类
if($id=="")
{
	$total=$mysql->rownums("select * from product");
	$url="product.php?";
	$sql="select * from product order by id desc limit $offset,$pagesize";
}
else
{
	$total=$mysql->rownums("select * from product where bigclassid=$id");
	$url="product.php?bigclassid=".$id."&";
	$sql="select * from product where bigclassid=$id order by id desc limit $offset,$pagesize";
}

//获取产品类
$mysql->query("select * from pclass");

while($arr=$mysql->fetcharray())
{
	$bigclass[]=$arr['id'].'$'.$arr['name'];
}

foreach($bigclass as $id=>$value)
{
	$bigclassname[$id]=explode("$",$value);
}

//获取产品列表

$mysql->query($sql);

while($arr=$mysql->fetcharray())
{
	$attach=explode(",",$arr["attach"]);
	
	//print_r($attach);
	
	//echo "select * from attachment where id='$attach[1]'";
	
	$attach=$mysql->onequery("select * from attachment where id='$attach[1]'");
	
	$product[]=$arr["id"]."$".$arr["title"]."$".$attach["attach"];
}

foreach($product as $id=>$value)
{
	$productlist[$id]=explode("$",$value);
}

//print_r($productlist);
//获取分页

$page=page($total,$pagesize,$url);

$tpl->assign("productlist",$productlist);

$tpl->assign("page",$page);

$tpl->assign("bigclassname",$bigclassname);

$tpl->display("product.tpl");



?>