<?php
$conn
=mysql_connect('127.0.0.1','root','');
mysql_query('
use
test',
$conn
);
mysql_query('set names utf8',
$conn
);
$perNumber
=3;
$page
=
$_GET
['page'];
$count
=mysql_query(
"select count(*) from kangbiao"
);
$rs
=mysql_fetch_array(
$count
);
$totalNumber
=
$rs
[0];
$totalPage
=
ceil
(
$totalNumber
/
$perNumber
);
if
(!isset(
$page
)) {
$page
=1;
}
$startCount
=(
$page
-1)*
$perNumber
;
$result
=mysql_query(
"select * from kangbiao limit $startCount,$perNumber"
);
echo
"<table border='1'>"
;
echo
"<tr>"
;
echo
"<th>id</th>"
;
echo
"<th>name</th>"
;
echo
"<th>age</th>"
;
echo
"<th>grade</td>"
;
echo
"</tr>"
;
while
(
$row
=mysql_fetch_array(
$result
)) {
echo
"<tr>"
;
echo
"<td>$row[0]</td>"
;
echo
"<td>$row[1]</td>"
;
echo
"<td>$row[2]</td>"
;
echo
"<td>$row[3]</td>"
;
echo
"</tr>"
;
}
echo
"</table>"
;
if
(
$page
!= 1) {
?>
<a href=
"02.php?page=<?php echo $page - 1;?>"
>上一页</a> <!--显示上一页-->
<?php
}
for
(
$i
=1;
$i
<=
$totalPage
;
$i
++) {
?>
<a href=
"02.php?page=<?php echo $i;?>"
><?php
echo
$i
;?></a>
<?php
}
if
(
$page
<
$totalPage
) {
?>
<a href=
"02.php?page=<?php echo $page + 1;?>"
>下一页</a>
<?php
}
?>