Home >Backend Development >PHP Tutorial >Perfect page turning function using air jump_PHP tutorial
It can be said that this is the most complete page turning function you have ever seen. The detailed content is explained in the code!
//Set the number of items in the list
$ListNum =25;
//Set the starting position
if($Start_Num==" "){
$Start_Num = 0;
}
//Set forward flip
$Begin_Num=$Start_Num-$ListNum;
//Set backward flip
$ End_Num=$Start_Num+$ListNum;
//Variable for calculating the number of items when turning pages
$n=0;
//Initial value of the generated list
$artList = "";
//Connect to the database (this example uses ODBC)!
$Conn = ODBC_CONNECT ("DSN", "user", "password");
$Sql = "SELECT field FROM table";
//Haha, it is inefficient to select everything here. What an exaggeration, but this is just to demonstrate our core content - turning pages!
$Result = $ODBC_DO($Conn, $sql);
while($odbc_fetch_row($Result)){
if( $n=$Start_Num){
$thevalue = ODBC_RESULT($Result,"field");
$artList.= $n.$thevalue."
";
}
$n++;
}
//Get the starting item of the last page
if($n % $ListNum == 0){
$lastPage = $n - $ListNum;
}else{
$lastPage = $n - $n % $ListNum;
}
//Always have the previous page
$artList.= "
|