程序|翻页
PHP代码:--------------------------------------------------------------------------------
//为了便于理解和更快地应用到工作中去,我们以MS SQL Server的NorthWind数据库Customers表为例。
$pageSize= 4; //每页显示的记录数
$hostname = "localhost"; //MSSQL Server
$dbuser = "sa"; //用户名
$dbpasswd = ""; //密码
//连接数据库
$conn = mssql_connect($hostname,$dbuser,$dbpasswd) or die("无法连接数据库服务器!");
//选择数据库,为了方便,这里以MSSQL Server的pubs数据库为例
$db = mssql_select_db("NorthWind",$conn) or die("无法连接数据库!");
//以Customers表为例,构建查询字符串
$sql = "SELECT * FROM Customers";
//执行查询语句
$res = mssql_query($sql) or die("无法执行SQL:$sql");
//$page变量标示当前显示的页
if(!isset($page)) $page=1;
if($page==0) $page=1;
//得到当前查询到的纪录数 $totalNum
$totalNum= mssql_num_rows($res);
if($totalNum{
echo "
没有纪录";
exit;
}
//得到最大页码数maxPage
$maxPage = (int)ceil($totalNum/$pageSize);
if((int)$page > $maxPage)
$page=$maxPage;
?>
".mssql_field_name($res,$i)." | " ;
".$row[$j]." | ";
$style = "2";
switch($style)
{
//格式: [首页] [上页] [下页] [末页]
case "1":
{
$out = "
$out .= "[共".$maxPage."页] [第".$page."页] ";
//首页和上页的链接
if( $totalNum>1 && $page>1)
{
$prevPage=$page-1;
$out .= " [首页] ";
$out .= " [上页] ";
}
//下页和末页的链接
if( $page>=1 && $page {
$nextPage= $page+1;
$out .= " [下页] ";
$out .= " [末页]";
}
$out .= "
echo $out;
}
break;
//格式: 1 2 3 4 5
case "2":
{
$linkNum = "4";//页面上显示连接的个数显示
$out = "
$start = ($page-round($linkNum/2))>0 ? ($page-round($linkNum/2)) : "1";
$end = ($page+round($linkNum/2)) if($page1)
$out .= "1 //for($t=1;$t for($t=$start;$t {
$out .= ($page==$t) ? "".$t." " : "$t ";
}
if($page$maxPage)
$out .= ">> $maxPage";
$out .= " 页
echo $out;
}
break;
//select下拉框直接跳转
case "3":
{
$out = "
$out .= "第 页";
$out .= "
echo $out;
}
break;
default:
echo "";
break;
}
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1
Easy-to-use and free code editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
