create table page1(
ID INT ( 10 ) not null auto_increment key ,
NAME varchar ( 50 ) not null
) ;
insert into page1( NAME) values ( "陈业贵" ) ;
insert into page1( NAME) values ( "陈业贵" ) ;
insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ;
insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ;
insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ; insert into page1( NAME) values ( "陈业贵" ) ;
< ! DOCTYPE html>
< html>
< head>
< meta http- equiv= "Content-type" content= "text/html;charset=utf-8" >
< / head>
< style type= "text/css" >
body{
font- size: 12 px; font- family: verdana; width: 100 % ;
}
div. page{
text- align: center;
}
div. content{
height: 300 px;
}
div. page a{
border:
}
div. page span. current{
border:
}
div. page span. disable{
border:
}
div. page form{
display: inline;
}
< / style>
< body>
<?php
error_reporting ( 'E_ALL&~E_NOTICE' ) ;
$page = $_GET [ 'p' ] ;
$host = "localhost" ;
$username = "root" ;
$password = "" ;
$db = "test2" ;
$pageSize = 10 ;
$showPage = 5 ;
$conn = mysqli_connect ( $host , $username , $password ) ;
if ( ! $conn ) {
echo "数据库连接失败" ;
exit;
}
mysqli_select_db ( $conn , $db ) ;
mysqli_query ( $conn , "SET NAMES UTF8" ) ;
$sql = "SELECT * FROM page order by id ASC LIMIT " . ( $page - 1 ) * $pageSize . ",{ $pageSize } " ;
$result = mysqli_query ( $conn , $sql ) ;
echo "<div class='content'>" ;
echo "<table border=1 cellspacing=0 width=30% align=center>" ;
echo "<tr><td>ID</td><td>NAME</td></tr>" ;
while ( $row = mysqli_fetch_assoc ( $result ) ) {
echo "<tr>" ;
echo "<td>{ $row [ 'ID' ] } </td>" ;
echo "<td>{ $row [ 'NAME' ] } </td>" ;
echo "<tr>" ;
}
echo "</table>" ;
echo "</div>" ;
mysqli_free_result ( $result ) ;
$total_sql = "SELECT COUNT(*)FROM page" ;
$total_result = mysqli_fetch_array ( mysqli_query ( $conn , $total_sql ) ) ;
$total = $total_result [ 0 ] ;
echo $total ;
$total_pages = ceil ( $total / $pageSize ) ;
mysqli_close ( $conn ) ;
$page_banner = "<div class='page'>" ;
$pageoffset = ( $showPage - 1 ) / 2 ;
if ( $page > 1 ) {
$page_banner . = "<a href='" . $_SERVER [ 'PHP_SELF' ] . "?p=1'>首页</a>" ;
$page_banner . = "<a href='" . $_SERVER [ 'PHP_SELF' ] . "?p=" . ( $page - 1 ) . "'><上一页</a>" ;
} else {
$page_banner . = "<span class='disable'>首页</span>" ;
$page_banner . = "<span class='disable'>上一页</span>" ;
}
$start = 1 ;
$end = $total_pages ;
if ( $total_pages > $showPage ) {
if ( $page > $pageoffset + 1 ) {
$page_banner . = "..." ;
}
if ( $page > $pageoffset ) {
$start = $page - $pageoffset ;
$end = $total_pages > $page + $pageoffset ? $page + $pageoffset : $total_pages ;
}
else {
$start = 1 ;
$end = $showPage ;
}
if ( $page + $pageoffset > $total_pages ) {
$start = $start - ( $page + $pageoffset - $end ) ;
}
}
for ( $i = $start ; $i <= $end ; $i ++ ) {
if ( $page == $i ) {
$page_banner . = "<span class='current'>{ $i } </span>" ;
}
else {
$page_banner . = "<a href='" . $_SERVER [ 'PHP_SELF' ] . "?p=" . $i . "'>{ $i } </a>" ;
}
}
if ( $total_pages > $showPage && $total_pages > $page + $pageoffset ) {
$page_banner . = "..." ;
}
if ( $page < $total_pages ) {
$page_banner . = "<a href='" . $_SERVER [ 'PHP_SELF' ] . "?p=" . ( $page + 1 ) . "'>下一页></a>" ;
$page_banner . = "<a href='" . $_SERVER [ 'PHP_SELF' ] . "?p=$total_pages '>尾页</a>" ;
} else {
$page_banner . = "<span class='disable'>尾页</span>" ;
$page_banner . = "<span class='disable'>下一页></span>" ;
}
$page_banner . = "共{ $total_pages } 页," ;
$page_banner . = "<form action='a.php' method='get'>" ;
$page_banner . = " 到第<input type='text' size=2 value='1' name='p'>页" ;
$page_banner . = "<input type='submit' value='确定'>" ;
$page_banner . = "</form>" ;
$page_banner . = "</div>" ;
echo $page_banner ;
?>
< / body>
< / html>