search
Homephp教程php手册求php的mssql翻页程序!

程序|翻页

PHP代码:--------------------------------------------------------------------------------



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;

?>




//显示表格头
for($i = 0; $i {
echo "" ;
}
?>


//根据偏移量($page - 1)*$pageSize,运用mssql_data_seek函数得到要显示的页面
if( mssql_data_seek($res,($page-1)*$pageSize) )
{
$i=0;
//循环显示当前纪录集
for($i;$i echo "";

//得到当前纪录,填充到数组$row;
$row= mssql_fetch_row($res);
if($row)
{
//循环显示当前纪录的所有字段值
for($j = 0;$j {
echo "";
}
}
echo "";
}
}
?>
".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;
}

?>




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

MantisBT

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

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function