Home > Article > Backend Development > A high-ai paging function and a url function_PHP tutorial
This paging function is very powerful
Just take a look and you will 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;
}
The following is the method to get the current url
function geturl() {
$headers = getallheaders();
$url = 'http://' .$headers['Host'].$SCRIPT_NAME;
return $url;
}