日期:2014-05-17  浏览次数:20484 次

php中分页代码
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Information</title>
</head>
<body>
<?php
include "sql_class.php" ;
$mysql=new Db_Mysql() ;
$mysql->dbConnect() ;
//$error=new Script() ;

$pageSize=2 ;
 $page_string = ""; 
 $totalpage="" ;
if( isset($_GET['page']) ){ 
  $page = intval( $_GET['page'] ); 

else{ 
  $page = 1; 
}
$sql="select count(*) as amount from $mysql->table order by id desc" ;
$result = mysql_query($sql); 
$amount = mysql_result($result , 0 , "amount"); 
if($amount){ 
  if($amount < $pageSize){ 
$totalpage = 1;

  if( $amount % $pageSize ){
  $totalpage = intval($amount / $pageSize) + 1; 
  }else{ 
  $totalpage = $amount / $pageSize;
  } 

else{ 
  $totalpage = 1; 

?>

<a href="add.html">添加留言</a></br>
<table width="100%" border="1" align="center" cellpadding="1" cellspacing="1">
  <tr>
  <th scope="col" width="5%" align="center">编号</th>
  <th scope="col" width="15%" align="center">留言者</th>
  <th scope="col" width="20%" align="center">主题</th>
<th scope="col" width="30%" align="center">内容</th>
  <th scope="col" width="10%" align="center">日期</th>
<th scope="col" width="10%" align="center">编辑</th>
<th scope="col" width="10%" align="center">删除</th>
  </tr>

  <?php
  $select="select * from $mysql->table limit (($page - 1) * $pageSize) , $pageSize " ;
$num=mysql_query($select) ;
第五十五行:while($info=mysql_fetch_array($num)){
?>
  <tr>
  <td align="center"><?php echo $info[id] ; ?></td>
  <td align="center"><?php echo $info[name] ; ?></td>
  <td><a href="show.php?id=<?php echo $info[id] ; ?>"><?php echo $info[title] ; ?></a></td>
  <td align="left"><?php echo $info[content] ; ?></td>
<td align="left"><?php echo $info[sqltime] ; ?></td>
<td align="center"><a href="update.php?id=<?php echo $info[id] ; ?>">编辑</a></td>
<td align="center"><a href="delete.php?id=<?php echo $info[id] ; ?>">删除</a></td>
  </tr>
  <?php
}
  if( $page >1 AND $page<$totalpage ){ 
  $page_string = "当前是第 $page 页|<a href= ?page=1>第一页</a>|<a href= ?page=($page-1)>上一页</a>| <a href=?page=($page+1)>下一页</a>|<a href=?page=$totalpage>尾页</a>"; 
  } 
  else if($page < 1){ 
  $page_string ="当前是第 $page 页|第一页|上一页" ;
  } 
  else if($page > $totalpage){
$page_string = "当前是第 $page 页|下一页|尾页"; 
  }
?>

<tr>
  <td colspan="7" scope="co