search
Homephp教程php手册无JS,完全php面向过程数据分页实现代码

无JS,完全php面向过程数据分页实现代码

Jun 13, 2016 am 11:58 AM
phpsessioncodePaginationcopyaccomplishdataLoginofset upprocessForpage

复制代码 代码如下:


//登陆页面设置的session,当session中存在name时
//session_start();
//$name = $_SESSION['name'];
//if (empty($name)){
// header("Location: error.php");
// exit();
//}
//面向过程, 数据分页显示
if(false!=($mysql = mysql_connect('本地mysql', 'mysql用户名', 'mysql密码'))){
mysql_query('set names utf8',$mysql); //设置数据库中的编码
mysql_select_db("数据库database",$mysql);
}else{
die("连接失败");
}


$pageSize = 10; //页面显示条数
$rowCount = 0; //数据总条数,从数据库获得

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

//取出数据条数
if(false!=($row=mysql_fetch_row($res1))){
$rowCount = $row[0];
}

//总页数,通过计算得到
$pageCount = 0;
$pageCount = ceil($rowCount/$pageSize);

//获取当前页
if(!isset($_GET['pageNow'])){ // 当 get/post都为空的时候赋默认值1
$pageNow = 1; //当前页数
}elseif(false!=is_numeric($_GET['pageNow']) && $_GET['pageNow']$pageNow = $_GET['pageNow'];
}else{
header("Location: ../Error/error.php");
exit();
}
//打印分页数据
echo "

";
echo "";
echo "       ";
$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 "      ";
}
echo "
idnameagesexbirthday编辑雇员删除雇员
{$row['id']}{$row['name']}{$row['age']}{$row['sex']}{$row['birthday']}编辑删除
";
//表单控制显示页数
echo "
";
//上一页按钮
if($pageNow>1){
$pageUp = $pageNow-1;
echo "上一页 ";
}

//下一页按钮
if($pageNow$pageDown = $pageNow+1;
echo "下一页 
";
}

//后退十页按钮
if($pageNow-10>0){
echo " ";
}


//向本页传递当前显示的页数,并显示第几页按钮
for($i=1;$i
if($i>$pageNow-2 && $iif($i!=$pageNow){
echo "
第".$i."页 ";
}
}
}

//前进十页
if($pageNow+10echo ">>> ";
}

//显示当前页与总页数
echo "
当前页".$pageNow."页/共".$pageCount."页";


//跳转页
echo "跳转到:";
echo "
";
echo "
";
?>
Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Atom editor mac version download

Atom editor mac version download

The most popular open source editor