No JS, complete PHP process data paging implementation code_PHP tutorial

WBOY
Release: 2016-07-21 15:16:25
Original
2267 people have browsed it

Copy code The code is as follows:

//Session set on the login page, when name exists in the session
//session_start();
//$name = $_SESSION['name'];
//if (empty($name)){
// header("Location: error .php");
// exit();
//}
//Process-oriented, data is displayed in pages
if(false!=($mysql = mysql_connect('local mysql', 'mysql username', 'mysql password'))){
mysql_query('set names utf8',$mysql); //Set the encoding in the database
mysql_select_db("database database",$mysql);
}else{
die("Connection failed");
}


$pageSize = 10; //Number of items displayed on the page
$rowCount = 0; / /Total number of data, obtained from the database

$sqlCount = 'select count(id) from employee';
$res1 = mysql_query($sqlCount,$mysql);

/ /Get the number of data items
if(false!=($row=mysql_fetch_row($res1))){
$rowCount = $row[0];
}

//Total The number of pages is calculated by
$pageCount = 0;
$pageCount = ceil($rowCount/$pageSize);

//Get the current page
if(!isset($_GET ['pageNow'])){ // When get/post are empty, assign the default value 1
$pageNow = 1; //Current page number
}elseif(false!=is_numeric($_GET[ 'pageNow']) && $_GET['pageNow']<=$pageCount){
$pageNow = $_GET['pageNow'];
}else{
header("Location: .. /Error/error.php");
exit();
}
//Print paging data
echo "
";
echo "";
echo "< tr> ;Edit employee";
$sqList = "select id,name,age,sex,birthday from employee limit ".($ pageNow-1)*$pageSize.",".$pageSize;
$res2 = mysql_query($sqList,$mysql);
while (false!=($row=mysql_fetch_assoc($res2))){
echo " < ;td>Edit ";
}
echo "
id name age Delete employee
{$row['id']} {$row['name']} { $row['age']} {$row['sex']} {$row['birthday']} Delete
";
//Form control display page number
echo "
";
/ /Previous page button
if($pageNow>1){
$pageUp = $pageNow-1;
echo " Previous page ";
}

//Next page button
if($pageNow<$pageCount){
$pageDown = $pageNow+1;
echo "Next page
";
}

// Back ten pages button
if($pageNow-10>0){
echo "<<< ";
}


//Pass the number of pages currently displayed to this page and display the page button
for($i=1;$i< ;=$pageCount;$i++){

if($i>$pageNow-2 && $i<$pageNow+6){
if($i!=$pageNow){
echo "Page ".$i." ";
}
}
}

//Forward ten pages
if($pageNow+10<=$pageCount){
echo " >>> ";
}

//Display the current page and total number of pages
echo "
Current page".$pageNow. "Pages/Total".$pageCount."Page";


//Jump to page
echo "Jump to:page";
echo "
";
echo "
";
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325919.htmlTechArticleCopy the code as follows: ?php //Session set on the login page, when name exists in the session//session_start (); //$name = $_SESSION['name']; //if (empty($name)){ // header("Location:...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!