大体程序如下,你自己调试一下吧
<?//把数据库的情况按照你的实际情况写入,
$link = mysql_connect("localhost", "mysql_user", "mysql_password")
or die("Could not connect: " . mysql_error());
// 获取当前页数,如果设定了,则按设定的显示,否则显示第一页
if( isset($_GET['page']) ){
$page = $_GET['page'] ;
}
else{
$page = 1;
}
$PageSize = 10;
$sql = "select count(*) as amount from tb_name";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$amount = $row['num'];
// 计算总共有多少页
if( $amount ){
if( $amount < $page_size ){ $page_count = 1; }
if( $amount % $page_size ){
$page_count = (int)($amount / $page_size) + 1;
}else{
$page_count = $amount / $page_size; }
}
else{
$page_count = 0;
}
// 翻页链接
$page_string = '';
if( $page == 1 ){
$page_string .= '第一页|上一页|';
}
else{
$page_string .= '<a href=?page=1>第一页</a>|<a href=?page='.($page-1).'>上一页</a>|';
}
if( ($page == $page_count) || ($page_count == 0) ){
$page_string .= '下一页|尾页';
}
else{
$page_string .= '<a href=?page='.($page+1).'>下一页</a>|<a href=?page='.$page_count.'>尾页</a>';
}
// 获取数据,以二维数组格式返回结果
if( $amount ){
$sql = "select * from table order by id desc limit ". ($page-1)*$page_size .", $page_size";
$result = mysql_query($sql);
while ( $row = mysql_fetch_row($result) ){
$rowset[] = $row;
//显示的代码不用我给你写了吧,你根据自己的情况写
}
}else{
echo "无内容!";
}
?>
[此贴子已经被作者于2005-12-13 14:56:23编辑过]