动态PHP分页

时间:2013-05-23 18:42:34

标签: php pagination

我在php中的分页代码只列出没有控制权的页面,如果我有100个页面,它会列出100个没有缩短的说法,例如1 2 3 ... 98 99 100,但是它会从1到100列出它而没有缩写,这是我的分页代码:

<?php
  $result = $myApp->dbTransaction("SELECT * FROM cause_lists;");

$getNum = mysql_num_rows($result);

$pg = $getNum/10;
$rem = ($getNum%10)/10;
if ($rem > 0) {
$pg -=$rem;
$pg +=1;
}

if ($pg == 2 || $pg > 2){
    $page_num = $pg;

} 
if (!empty($page_num)){
    if ($range_filter === 0){$arrow_class_1 = "arrow unavailable";
    $arrow_link_1 = "#";
    } 

    else {$arrow_class_1 = "arrow";
    $r = $range_filter + 0;
    $arrow_link_1 ="cl_admin.php?range=$r";
    }

    if ($range_filter != (($pg * 10) - 10)) {$arrow_class_2 = "arrow"; $arrow_link_2 ="#";
    $r = $range_filter + 20;
    $arrow_link_2 ="cl_admin.php?range=$r";
    }
    else {$arrow_class_2 = "arrow unavailable";
    $arrow_link_2 ="#";
    }
    echo " <ul class=\"pagination\"><li class=\"$arrow_class_1\"><a href=\"$arrow_link_1\">&laquo;</a></li>";
    for($i=1; $i<=$page_num; $i++){
        $rge = $i * 10;
        if(($range_filter+10) === $rge){$page_class = "current";} else {$page_class = "";}
        echo "<li class='$page_class'><a href=\"cl_admin.php?range=$rge\">$i</a></li>";
    }
    echo "<li class=\"$arrow_class_2\"><a href=\"$arrow_link_2\">&raquo;</a></li></ul>";
}

  ?>

1 个答案:

答案 0 :(得分:0)

您可以尝试我的分页库。 http://www.okvee.net/articles/%E0%B9%81%E0%B8%9A%E0%B9%88%E0%B8%87%E0%B8%AB%E0%B8%99%E0%B9%89%E0%B8%B2%E0%B9%81%E0%B8%AA%E0%B8%94%E0%B8%87%E0%B8%9C%E0%B8%A5%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-pagination-class

抱歉,该文件是泰语,但我相信您可以轻松理解。

设置$ config ['num_links']以显示可见的页数。