<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="col" width="5%" align="center"><?php echo $page_string ; ?></td>
</tr>
</table>
<?php
//mysql_free_result($result) ;
mysql_free_result($num) ;
$mysql->db_close() ;
?>
</body>
</html>调试时出现的问题:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\www\zwt\lyb\index.php on line 55

解决方案 »

  1.   

    $num=mysql_query($select);这里执行错误
    你把 你最后执行的sql语句打印出来放到数据库上执行哈 看看返回的是不是有错误 
      

  2.   

    这是错误的
     $select="select * from $mysql->table limit (($page - 1) * $pageSize) , $pageSize " ;
    应写为
     $select="select * from $mysql->table limit ". (($page - 1) * $pageSize). " , $pageSize " ;把复杂的表达式写在 limit 子句中,会产生 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 错误