function getpage($sql,$page_size=20)
{
global $page,$totalpage,$sums; //out param
$page = $_GET["page"];
//$eachpage = $page_size;
$pagesql = strstr($sql," from ");
$pagesql = "select count(*) as ids ".$pagesql;
$result = mysql_query($pagesql);
if($rs = mysql_fetch_array($result)) $sums = $rs[0];
$totalpage = ceil($sums/$page_size);
if((!$page)($page $startpos = ($page-1)*$page_size;
$sql .=" limit $startpos,$page_size ";
return $sql;
}
function showbar($string="")
{
global $page,$totalpage;
$out="共
".$totalpage."页 ";
$linkNum =4;
$start = ($page-round($linkNum/2))>0 ? ($page-round($linkNum/2)) : "1";
$end = ($page+round($linkNum/2)) $prestart=$start-1;
$nextend=$end+1;
if($page1)
$out .= "
第一页 ";
if($start>1)
$out.="
.. ";
for($t=$start;$t {
$out .= ($page==$t) ? "[".$t."] " : "$t ";
}
if($end$out.="
>>..";
if($page$totalpage)
$out .= "
最后页";
return $out;
}