<?php 
require_once 'conn.php';
require_once 'function.php';
$b='新闻';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0"/>
<title><?=$b?>-天天链接网</title>
<meta name="baidu-site-verification" content="esPVnGS3hJ" />
<link rel="stylesheet" href="css/index.css">
<link rel="stylesheet" href="page.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
</head>
 
<body>
<?php 
require_once 'head.php';
?>
<div class="container">
  <div class="box">  		
    <div class="row">
         <div class="panel panel-default">
			<div class="panel-heading">
				<h3 class="panel-title">
					<a href="showlist.php">最新资讯</a>
					<span class="badge" style="background-color:#FFFFFF; float:right;"><a href="showlist.php">更多</a></span> 
				</h3>				
			</div>
			<div class="panel-body">
			<?php
						// Page分页函数 
					$page = $_GET["page"]; 
					$typename=$_GET['typename'];
					  if($typename){
						$m=" where typename = '$typename' ";
					  }
					function Page($rows,$page_size,$typename){ 
					global $page,$select_from,$select_limit,$pagenav,$typename;
					$page_count = ceil($rows/$page_size); 
					if($page <= 1 || $page == '') $page = 1; 
					if($page >= $page_count) $page = $page_count; 
					$select_limit = $page_size; 
					$select_from = ($page - 1) * $page_size.','; 
					$pre_page = ($page == 1)? 1 : $page - 1; 
					$next_page= ($page == $page_count)? $page_count : $page + 1 ; 
					$pagenav .= "第 $page/$page_count 页 共 $rows 条记录 "; 
					$pagenav .= "<a href='?page=1&typename=$typename'>首页</a> "; 
					$pagenav .= "<a href='?page=$pre_page&typename=$typename'>前一页</a> "; 
					$pagenav .= "<a href='?page=$next_page&typename=$typename'>后一页</a> "; 
					$pagenav .= "<a href='?page=$page_count&typename=$typename'>末页</a>"; 
					$pagenav.="　跳到<select name='topage' size='1' onchange='window.location=\"?typename=$typename&page=\"+this.value'>\n"; 
					for($i=1;$i<=$page_count;$i++){ 
					if($i==$page) $pagenav.="<option value='$i' selected>$i</option>\n"; 
					else $pagenav.="<option value='$i'>$i</option>\n"; 
					}
					$pagenav.="</select>"; 
					} // Page分页函数 
					// 使用示例 
					
					$num=query("select count(id) from news $m");							
					Page($num[0],20,$typename); 
					$sql = "select * from news $m order by id desc limit $select_from $select_limit"; 					
					$arr = listquery($sql);						
					foreach ($arr as $v) {
					?>
				<div class="media">
   					<div class="media-body">
						<h4 class="media-heading"><a href="show.php?id=<?=$v[id]?>"><?=$v['title']?></a></h4>
						
						<p>发布时间：<font color="red"><?=$v['time']?></font> 点击：<?=$v['click']?></p>
					</div>
				</div>
								
			<?php }?>	
			
        </div>
	  </div>
		
    </div>

	
	<div class="row">
         <div class="panel panel-default">
			<div class="panel-body">
				<?php
                    echo $pagenav;           
                ?>
			</div>
		</div>
    </div>
 
	<?php 
	require_once 'foot.php';
	?>
	
	<!--我的代码结束-->
  </div>
</div>

</body>
 
</html>
