bimoweb

talk about web

Script PHP Paging

Post date Jun 13th, 2008

Bagi yang membutuhkan script paging, dibawah ini bisa dipakai. Sebenarnya ini bukan buatan ku sendiri. Saya sendiri menggunakan dengan logika akal bulus untuk paging. Sampai sekarang saya masih menggunakan paging saya tersebut. Kalau saya membagikan script paging saya tersebut, takutnya tidak valid meskipun bisa memberikan hasil yang valid. Nah kalau yang ini benar-benar valid. Silahkan rampok script dibawah ini.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<html>
<head>
<title>Implementing Paging with next and prev</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
 
<body>
<?php
include '../library/opendb.php'; // sesuaikan dengan konfigurasi database kamu
 
// how many rows to show per page
$rowsPerPage = 20;
 
// by default we show first page
$pageNum = 1;
 
// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
	$pageNum = $_GET['page'];
}
 
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
 
$query  = "SELECT val FROM randoms LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die('Error, query failed');
 
// print the random numbers
while(list($val) = mysql_fetch_array($result))
{
	echo "$val <br>";
}
 
echo '<br>';
 
// how many rows we have in database
$query   = "SELECT COUNT(val) AS numrows FROM randoms";
$result  = mysql_query($query) or die('Error, query failed');
$row     = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
 
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
 
$self = $_SERVER['PHP_SELF'];
 
// creating 'previous' and 'next' link
// plus 'first page' and 'last page' link
 
// print 'previous' link only if we're not
// on page one
if ($pageNum > 1)
{
	$page = $pageNum - 1;
	$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
 
	$first = " <a href=\"$self?page=1\">[First Page]</a> ";
} 
else
{
	$prev  = ' [Prev] ';       // we're on page one, don't enable 'previous' link
	$first = ' [First Page] '; // nor 'first page' link
}
 
// print 'next' link only if we're not
// on the last page
if ($pageNum < $maxPage)
{
	$page = $pageNum + 1;
	$next = " <a href=\"$self?page=$page\">[Next]</a> ";
 
	$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
} 
else
{
	$next = ' [Next] ';      // we're on the last page, don't enable 'next' link
	$last = ' [Last Page] '; // nor 'last page' link
}
 
// print the page navigation link
echo $first . $prev . " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages " . $next . $last;
?>
</body>
</html>

Sebagai catatan, script tersebut diambil disini

Related Post

Tagged as: , , , , , , , ,
Filled in category Belajar web, Blogging, Cerita-Cerita, PHP, Teknologi
Bookmark and Share

Ingin membaca artikel lewat email ? Masukkan email anda
  

RSS feed | Trackback URI

4 Comments »

Comment by Mara Mei
2008-06-17 02:37:18

Dulu juga pernah bikin script kaya gini, tapi intinya hampir sama dengan script ini.

 
Comment by tipis
2008-06-17 10:12:37

wah tengkiyu mas, kadang memang butuh paging untuk menampilkan banyak data. saya save ya :D

 
Comment by tomy
2008-06-22 11:05:10

wahhh…. makasih !!!!!!!!! banyakin tutornya yah

 
Comment by human IT
2008-07-08 06:06:18

mas thanks ya untuk script nya….kalo ada yang baru tutorial PHPnya boleh minta ga?????

 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.
Search Term
contoh print php coding, contoh paging, contoh paging dengan php, PHP:Paging 1 0 download, paging script php, bimoweb php paging, pilih diantara tanggal PHP MySQL, PAGING PHP NEXT PREV, fs yang menggunakan script, script FS, php db paging script, kumpulan script fs, contoh html script, script fs, script visitor fs, paging php script, Script fs, script PHP paging google, php paging, script lagu FS, paging php ala google, paging php, fs script,