Phân trang trong php cho anh em cần!


function pagination($show = 10){
global $dbc;
global $start;
if (isset($_GET[‘p’]) && filter_var($_GET[‘s’], FILTER_VALIDATE_INT, array(‘min_rage’ => 1))) {
$page = $_GET[‘p’];
} else {
$s = “select count(id) from products”;
$r = mysqli_query($dbc, $s);
confirm_query($r, $s);
list($record) = mysqli_fetch_array($r, MYSQL_NUM);
if ($record > $show) {
$page = ceil($record / $show);
} else {
$page = 1;
}
}
$output = “<ul class=’phantrang’>”;
if($page > 1){
$current_page = ($start / $show) + 1;
if ($current_page != 1) {
$output .= “<li><a href=’?s=” . ($start – $show) . “‘>Previous</a></li>”;
}//#Pre

for ($i = 1; $i <= $page; $i++) {
if ($i != $current_page) {
$output.= “<li><a href=’?s=” . ($show * ($i – 1)) . “&p={$page}’>{$i}</a></li>”;
} else {
$output.= “<li>{$i}</li>”;
}
}// 1 2 3 4 5 6 7

if ($current_page != $page) {
$output.= “<li><a href=’?s=” . ($start + $show) . “‘>Next</a></li>”;
} //#Next
$output.= “</ul>”;
}
return $output;
}

Advertisements

Để lại comment đê!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s