First ....4,5,6,7,8... Last
Atau 1,2,3,4,5...Last
Atau ...15,16,17,18,19
Source code :
$global_db = mysql_connect('localhost', $username, $password);
mysql_select_db($dbname, $global_db);
// query to get the number of records
$query = "SELECT Field1, Field2 FROM $TABLE";
$result = mysql_query($query) or die("ERROR");
$num_record = mysql_num_rows($result);
if($num_record > $display) { // Only show 1,2,3,etc. when there are more records found that fit on 1 page
// when the page is loaded first...
if(empty($pagenr)) {
$pagenr = 1;
}
// some variables
$display = 10; // number of records to display per page
$max_pages_to_print = 7; // number of pages to show, if you change this you also have to change the variable 'middlenumber', for example:increase this one with two, increase middlenumber with one
$startrecord = $pagenr * $display; // first record to show from the queryresult
$num_pages = intval($num_record / $display) + 1; // total number of pages
$loopcounter = 0; // counter for whileloop
$currentpage = $pagenr; // Page where we are at the moment
$middlenumber = 3; // Number will be decreased from variable currentpage in order to get the currentpage always in the middle
$colourcounter = 0; // Variable to change the background-color of the
$i = 1; // variable that will print 1,2,3,etc..
$x = 0; // variable i use to put always the current, marked page in the middle
// actual stuff starts here
print("
First... | ");$i | "); // print pagenumbers$ i | "); // print pagenumbers$i | "); // print pagenumbers$ i | "); // print pagenumbers... | ");
$startrecord = $startrecord - $display; // Set startrecord to the right position
// Some calculation for the lastrecord
if($currentpage == $num_pages) { // Last page...
$lastrecord = $num_record; // so $lastrecord = $num_record
}
else {
$lastrecord = ($currentpage * $display);
}
} // End of the first if-statement
// Some info
print("
You are now on page $currentpage |
There are $num_pages pages in total |
$num_record records are spread over $num_pages pages |
Current display : $startrecord - $lastrecord |
// End info
// actual query, watch the end($startrec
// ord, $display)
$query2 = "SELECT Field1, Field2 FROM $TABLE LIMIT $startrecord, $display";
$result2 = mysql_query($query2) or die("ERROR");
Queryresult PHP
// print results on screen
print("
< color="#FFFFFF">Fieldname1 | Fieldname2 |
$Field1 | $Field2 |
Sebelum menulis coding, ubahlah nama username, password dan dbname, untuk koneksi ke database Anda
Keterangan variabel :
* $display : jumlah dari record yang akan ditampilkan per halaman
* $max_pages_to_print : jumlah halaman yang akkan dicetak(1,2,3,dsb)
* $middlenumber : hanya diubah ketika Anda mengubah variable $max_pages_to_print. Sebagai contoh, jika Anda menambah $max_pages_to_print dengan 2, maka tambahkan juga $middlenumber dengan 1. Begitu pula jika $max_pages_to_print dikurangi menjadi 2, maka kurangilah $middlenumber dengan 1
2 comments:
,,addu...kok ribet ci,,
,,akku mce gag tw makcutnya,,,pendekar berkuda,,
,
,bhahahahaha,
wah... dah jago PHP nih kayaknya...
Post a Comment
leave comments..!!