Untuk membuat paging anda boleh menggunakan contoh koding seperti di bawah.
Pertama masukkan koding ini.
$maxRows = 10;
$pageNum = 0;
if (isset($_GET['pageNum'])) {
$pageNum = $_GET['pageNum'];
}
$startRow = $pageNum * $maxRows;
Kedua masukkan koding ini
mysql_select_db($database);
$query_abc = "SELECT * FROM abc";
$query_limit_abc = sprintf("%s LIMIT %d, %d", $query_article, $startRow, $maxRows);
Ketiga masukkan koding ini
if (isset($_GET['totalRows_abc'])) {
$totalRows_abc = $_GET['totalRows_abc'];
} else {
$all_ = mysql_query($query_abc);
$totalRows_abc = mysql_num_rows($all_abc);
}
$totalPages = ceil($totalRows_abc/$maxRows)-1;
$queryString_abc= "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum") == false &&
stristr($param, "totalRows_abc") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_abc= "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_abc= sprintf("&totalRows_registration=%d%s", $totalRows_abc, $queryString_abc);
Ini untuk bahagian design paging.
<input 0="" currentpage="" id="bb" name="bb" onclick="location.href='<?php printf(" pagenum="%d%s" querystring_abc="" s="" type="button" value="|<" />'"/>
<input -="" 1="" currentpage="" id="b" max="" name="b" onclick="location.href='<?php printf(" pagenum="" querystring_abc="" s="" type="button" value="<" />'"/>
Page: of
<input 1="" currentpage="" id="d" min="" name="d" onclick="location.href='<?php printf(" pagenum="" querystring_abc="" s="" totalpages="" type="button" value=">" />'" />
<input currentpage="" id="dd" name="dd" onclick="location.href='<?php printf(" pagenum="%d%s" querystring_abc="" s="" totalpages="" type="button" value=">|" />'" />
Total ABC :
Tuesday, 1 October 2013
Cara membuat paging menggunakan PHP
10:05 am
No comments
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment