/** * @param int $page * @param int $end * @param bool $allRecords */ public static function calculate($page, $end = 20, $allRecords = false) { self::$page = intval($page); self::$countPage = ceil($allRecords / $end); self::$end = $end; self::$allRecords = $allRecords; if (self::$page <= 1 or self::$page > self::$countPage) { self::$page = 1; self::$start = 0; } else { self::$start = (self::$page - 1) * self::$end; } }
<?php include 'config.php'; $max = 6; $select = "SELECT * FROM test"; $query1 = mysql_query($select) or die(mysql_error()); $total = mysql_num_rows($query1); $nav = new Pagination($max, $total, $_GET['p']); $nav->url = 'normal.php?p='; $query2 = mysql_query($select . " LIMIT " . $nav->start() . "," . $max) or die(mysql_error()); while ($item = mysql_fetch_object($query2)) { echo $item->id . ' - <b>' . $item->name . '</b><br />'; } echo $nav->get_html();