Home > php教程 > php手册 > 用空跳实现的完美的翻页功能

用空跳实现的完美的翻页功能

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:24:33
Original
1380 people have browsed it

可以说,这是你见到的最完善的翻页功能,详细的内容在代码中解释!

//设定列表的条数
$ListNum =25;

//设置起始位置
if($Start_Num==""){
$Start_Num = 0;
}

//设置前翻
$Begin_Num=$Start_Num-$ListNum;
//设置后翻
$End_Num=$Start_Num+$ListNum;


//翻页时计算条数的变量
$n=0;

//生成的列表初始值
$artList = "";

//连接数据库(本例使用ODBC)!
$Conn = ODBC_CONNECT ("DSN","user","password");
$Sql = "SELECT field FROM table";
//呵呵,这里全部select出来,毫无效率,好夸张,不过这只是为了演示我们的中心内容——翻页!

$Result = $ODBC_DO($Conn,$sql);

while($odbc_fetch_row($Result)){
if( $n=$Start_Num){
$thevalue = ODBC_RESULT($Result,"field");
$artList.= $n.$thevalue."
";
}
$n++;
}

//获得最后一页的起始项
if($n % $ListNum == 0){
$lastPage = $n - $ListNum;
}else{
$lastPage = $n - $n % $ListNum;
}
//始终有最前一页
$artList.= "
|



//只有Start_Num大于0,才能有上一页
if($Start_Num > 0){
$artList.= "}else{
$artList.= "}

//如果Start_Num已经在最后一页的范围内,不能有下一页
if($Start_Num $artList.= "下一页>>  ";
}else{
$artList.= "下一页>>  ";
}

//始终有最后一页
$artList.= "最后一页>|
";

echo $artList;
?>
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template