Home >Backend Development >PHP Tutorial >PHP high AI paging function and url function
This paging function is very powerful
Just take a look and you’ll know
function ppage($total, $page, $e_page = 15, $e_block = 10, $url = '', $color = '') {
if(!strpos($url,'?'))
$url.='?';
else
$url.='&';
if($color<>'') {
$color ='';
$colore = '';
}
$totalpage = ceil($total/$e_page); //Number of pages
$p_block = ceil($totalpage/$e_block); //Number of blocks
$n_block = ceil($page/$e_block); //Now block
$start = ($n_block-1)*$e_block+1;
$ended = $n_block*$e_block;
if($ended>$total)
$ended = $totalpage;
if($n_block>1) {
$link = $start-1;
$head =''.$color.'[<=]'.$colore.' ' ;
}
if($n_block<$p_block) {
$link = $ended+1;
$foot = ''.$color.'[=>]'.$colore.'';
}
for($i=$start;$i<=$ended;$i++) {
$middle .=''.$color.'['.$i.']'.$colore.'
}
return $head.$middle.$foot;
}
Here is how to get the current url
function geturl() {
$headers = getallheaders();
$url = 'http://'.$headers['Host'].$SCRipT_NAME;
return $url;
}
The above introduces the paging function and url function of PHP high AI, including the content of paging function. I hope it will be helpful to friends who are interested in PHP tutorials.