PHP List Page Display method

Source: Internet
Author: User

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">








<meta http-equiv= "Content-type" content= "text/html; charset=utf-8"/>


<title>untitled document</title>








<body>


<style type= "Text/css" >


    *{  


margin:0;


padding:0;


    }  


#lay {


margin:100px 100px 100px 100px;


    }  


a{


padding:5px;


font-size:13px;


Text-decoration:none;


    }  


span{


font-size:13px;


    }  


table{


border:1px solid red;


Border-collapse:collapse;


    }  


</style>


Id

Value

  

  

$link = mysql_connect ("localhost", "root", ""); Connecting to a database

mysql_select_db ("CS");//Select which database

mysql_query ("Set names Utf-8"); Set database character encoding to Chinese

$sql = mysql_query ("Select *from Persons");

$pagesize = 5; Show number of bars

$sum = mysql_num_rows ($sql); Determine how many data there are

$count = Ceil ($sum/$pagesize)//Find out how many pages there are

$pages = $count; Show last Page

$init = 1;

$page _len = 7;

$max _p = $count;

if (Empty ($_get["page") | | | $_get["page"]<0) {

$page = 1;

}else{

$page = $_get["page"];

}

$off = ($page-1) * $pagesize; Find the first data for a database query

$he = mysql_query ("SELECT * from persons limit $off, $pagesize");//start with off, show to pagesize law

echo "altogether". $sum. "Data";

while ($row = Mysql_fetch_array ($he)) {

echo "";

echo "". $row [' id ']. "";

echo "". $row [' FirstName ']. "";

echo "";

}

?>

  

$page _len = ($page _len%2)? $page _len: $page _len+1;//If 1 is true, 0 is False

$pageoffset = ($page _len-1)/2;//page number offset

$key = "";

if ($page!=1) {

$key. = "First page";

$key. = "Previous page";

}else{

$key. = "First page";

$key. = "Previous page";

}

if ($pages > $page _len) {

if ($page <= $pageoffset) {

$init = 1;

$max _p = $page _len;

}else{

if ($page + $pageoffset >= $pages + 1) {

$init = $pages-$page _len+1;

}else{

$init = $page-$pageoffset;

$max _p = $page + $pageoffset;

}

}

}

for ($i = $init; $i <= $max _p; $i + +) {

if ($i = = $page) {

$key. = "[". $i. "]";

}else{

$key. = "$i";

}

}

if ($i -1!= $page) {

$key. = "Next page";

$key. = "Last page";

}else{

$key. = "Next page";

$key. = "Last page";

}

echo "";

echo "". $key. "";

echo "";

?>

  

  

  

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.