Last active
August 27, 2015 13:12
-
-
Save vihoangson/a72646c2470d86ce3619 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* paranation | |
* | |
* params["page"] | |
* params["per_page"] | |
* params["all_row"] | |
* params["distance"] | |
* params["link"] | |
* @return void | |
* @author | |
**/ | |
function paranation($params){ | |
extract($params); | |
if($all_row < $per_page){ | |
return ""; | |
} | |
$all_page = round($all_row/$per_page); | |
$offset = $page*$per_page; | |
$distance = ($distance<5?5:$distance); | |
$page_li =array(); | |
$page_li[] =1; | |
if($page>$distance + 1){ | |
$page_li[]="..."; | |
} | |
for($i=2;$i<$all_page;$i++){ | |
if($i > $page-$distance && $i < $page+$distance ){ | |
$page_li[]=$i; | |
} | |
} | |
if($page<$all_page-$distance ){ | |
$page_li[]="..."; | |
} | |
$page_li[] = $all_page; | |
$html = ""; | |
foreach ($page_li as $key => $value) { | |
$html .= "<li><a ".( (is_numeric($value) && $page != $value) ? "href='".$link.$value :"." )." '>".$value."</a></li>"; | |
} | |
return $html; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment