1. ランダムな文字列関数を生成します
function getpage($sql,$page_size=20)
{
global $page,$totalpage,$sums; //out param
$page = $_GET["page"];
//$eachpage = $page_size;
$pagesql = strstr($sql," from ");
$pagesql = 「ID として count(*) を選択」.$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 ";
$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))<$totalpage ? ($page+round($linkNum/2)) : $totalpage;
$prestart=$start-1;
$nextend=$end+1;
if($page<>1)
$out .= "
第一页 ";
if($start>1)
$out.="
..<< ";
for($t=$start;$t<=$end;$t++)
{
$out .= ($page==$t) ? "
[".$t."] " : "
$t ";
}
if($end<$totalpage)
$out.="
> ;>..";
if($page<>$totalpage)
$out .= "
最終後页";
$out を返す;
}