<?php  
require_once("config.php");
require_once("conn.php");

$sql=mysql_query("select count(*) as total1 from tb_commodity ",$conn);
$info=mysql_fetch_array($sql);
$total1=$info[total1];
if(empty($_GET[pages])==true || is_numeric($_GET[pages])==false){
	$page1=1;
}else{
	$page1=intval($_GET[pages]);
}
if($total1==0){
	echo "<div align=center>暂无商品</div>";
}else{ 
	$pagesize1=10;
	if($total1<$pagesize1){
		$pagecount1=1;
	}else{
		if($total1%$pagesize1==0){
			$pagecount1=intval($total1/$pagesize1);
		}else{
			$pagecount1=intval($total1/$pagesize1)+1;
		} 
	}
$smarty->assign("total1",$total1);			//通过assign方法将数组$array中的数据写入到myrow中      
$smarty->assign("pagesize1",$pagesize1);			//通过assign方法将数组$array中的数据写入到myrow中      
$smarty->assign("page1",$page1);			//通过assign方法将数组$array中的数据写入到myrow中      
$smarty->assign("pagecount1",$pagecount1);			//通过assign方法将数组$array中的数据写入到myrow中      

}

$query=mysql_query("select * from tb_commodity order by tb_commodity_id desc limit ".($page1-1)*$pagesize1.",$pagesize1",$conn );
$myrow=mysql_fetch_array($query);
$array=array();								//定义一个空数组
do{
   array_push($array,$myrow);				//将获取的数组值写入到新的数组中
}while($myrow=mysql_fetch_array($query));	//循环读取数据库中数据

$smarty->assign("myrow",$array);			//通过assign方法将数组$array中的数据写入到myrow中

$smarty->display("index.tpl");
?>