<?
error_reporting(0);

include("global.php");

//初始化变量

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

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

$pagesize=10;

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

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

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

//获取新闻类
$mysql->query("select * from nclass");

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

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

//获取新闻列表

$mysql->query($sql);

while($arr=$mysql->fetcharray())
{
	$newslist[]=$arr["id"]."$".$arr["title"]."$".$arr["time"];
}

foreach($newslist as $id=>$value)
{
	
	$newslist[$id]=explode("$",$value);
	
}
//print_r($newslist);
//获取分页函数

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


//smarty注册

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

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

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

$tpl->display("news.tpl");
?>