答案:下面是一个简单的php连接mysql数据库进行数据分页显示的模版.可以按注释说明信息进行修改,里面的sql语句是可以自己改的.
注意分析和观察里面相关分页部分的代码的书写和实现的方式.
<?php
$link
=
mysql_connect('localhost',
'root',
'')
or
die('mysql
database
connect
error');
mysql_select_db('your
database')
or
die('the
selected
database
is
not
exist');
?>
//这里插入你的html代码,
<?php
$sql
=
'select
count(*)
count
from
your_table';
$result
=
mysql_query($sql)
or
die(mysql_errno().":
".mysql_error()."\n");
$rs=mysql_fetch_object($result);
$recountCount
=
$rs->count;
$show
=
20;
$totalPage
=
ceil($recountCount/$show);
$page
=
(isset($_GET['page'])
&&
$_GET['page']>=0)?
$_GET['page']:
0;
$isLast
=
($page==($totalPage-1))?
true:
false;
$hasNoPre
=
($page==0)?
true:
false;
$hasNoNext
=
($page==$totalPage-1)?
true:
false;
$isFirst
=
($page==0)?
true:false;
$start
=
$page*$show;
mysql_free_result($result);
?>
//这里插入你的html代码,
<?
$sql
=
"select
*
from
your_table
limit
$start,$show";
$result
=
mysql_query($sql)
or
die(mysql_errno().":
".mysql_error()."\n");
while($rs=mysql_fetch_object($result)){
//这个循环里的html代码自己更具实际情况修改
echo
$rs->art_id;
echo
"<br>";
}
mysql_free_result($result);
?>
<?
$str
= "共 $recountCount 条记录,当前第 ".($page+1)."/$totalPage 页";
$str .= $isFirst?
"首页"
: "<a href=>首页</a>";
$str .= $hasNoPre?
"上一页" : "<a href=>上一页</a>";
$str .= $hasNoNext? "下一页" : "<a href=>下一页</a>";
$str .= $isLast?
"尾页"
: "<a href=>尾页</a>";
echo $str;
?>