Use the limit attribute of SQL for mysql database // use the limit attribute of SQL for mysql database
<? PHP
Function pagetorecord ($ page, $ pagecounts ){
$ Result = ($ page-1) * $ pagecounts;
Return $ result;
}
Function pagech ($ page, $ j ){
If ($ j = 1 ){
$ P = $ page + 1 ;}
Else {
$ P = $ page-1 ;}
Return $ p;
}
$ Pagecounts = 20;
If ($ startpage ){
$ Startpage = $ startpage;
}
Else {
$ Startpage = 1;
}
$ Sqltr = "select * from main order by sm limit". pagetorecord ($ startpage, $ pagecounts). ",". $ pagecounts;
$ Connect = mysql_connect ("localhost", "http", "something ");
$ Select = mysql_select_db ('book', $ connect );
$ Query = mysql_query ('SELECT count (*) as total from main', $ connect );
$ Totalrecord = mysql_result ($ query, 0, "total ");
$ Query = mysql_query ($ sqltr, $ connect );
//-------------------------------
Echo "<table border = 1 cellpadding = 0 cellspacing = 0> ";
Echo "<tr> <td> No. </td> <td> Standard Book Number </td> <td> title </td> <td> Press </td> <td> pricing </td> </tr> ";
$ I = 1;
While ($ array = mysql_fetch_array ($ query )){
Printf ("<tr> <td> % d </td> <td> % s </ td> <td> % f </td> </tr> ",
$ I, $ array [bzsh], $ array [sm], $ array [cbs], $ array [dj]);
$ I ++;
}
Echo "</table> ";
Echo "Mysql_close ($ connect );
If (0 = $ totalrecord % $ pagecounts ){
$ Totalpage = floor ($ totalrecord/$ pagecounts );}
Else {
$ Totalpage = floor ($ totalrecord/$ pagecounts) + 1;
}
// Echo $ sqltr;
If ($ startpage = 1 ){
If ($ totalpage> 1 ){
Echo "homepage ";
Echo "previous page ";
Echo "<a href =.../". basename ($ PHP_SELF )."? Startpage = ". pagech ($ startpage, 1)."> Next page </a> ";
Echo "<a href =.../". basename ($ PHP_SELF )."? Startpage = ". $ totalpage."> Last page </a> ". $ totalpage." page ". $ startpage." page ";
}
Else {
Echo "homepage ";
Echo "previous page ";
Echo "next page ";
Echo "last page ";
}
}
Elseif ($ startpage ==$ totalpage ){
Echo "<a href =.../". basename ($ PHP_SELF )."? Startpage = 1> homepage </a> ";
Echo "<a href =.../". basename ($ PHP_SELF )."? Startpage = ". pagech ($ startpage,-1)."> Previous Page </a> ";
Echo "next page ";
Echo "end page". $ totalpage. "page". $ startpage. "page ";
}
Else {
Echo "<a href =.../". basename ($ PHP_SELF )."? Startpage = 1> homepage </a> ";
Echo "<a href =.../". basename ($ PHP_SELF )."? Startpage = ". pagech ($ startpage,-1)."> Previous Page </a> ";
Echo "<a href =.../". basename ($ PHP_SELF )."? Startpage = ". pagech ($ startpage, 1)."> Next page </a> ";
Echo "<a href =.../". basename ($ PHP_SELF )."? Startpage = ". $ totalpage."> Last page </a> ". $ totalpage." page ". $ startpage." page ";
}
?>