Php5mysql paging instance code. Copy the code as follows :? Php connection database $ dbmysql_connect (localhost, root,); mysql_select_db (hy, $ db); set the number of records displayed on each page $ pagesize25; get Records
The code is as follows:
// Connect to the database
$ Db = mysql_connect ("localhost", "root ","");
Mysql_select_db ("hy", $ db );
// Set the number of records displayed on each page
$ Pagesize = 25;
// Obtain the total number of records and calculate the total number of pages
$ Res = mysql_query ("select count (*) from main", $ db );
$ Myrow = mysql_fetch_array ($ res );
$ Numrows = $ myrow [0];
// Calculate the total number of pages
$ Pages = intval ($ numrows/$ pagesize );
If ($ numrows % $ pagesize)
$ Pages ++;
// Determine whether the page number is set or not. if not, the page number is defined as the homepage.
If (! Isset ($ page ))
$ Page = 1;
// Determine the number of pages to be transferred
If (isset ($ ys ))
If ($ ys> $ pages)
$ Page = $ pages;
Else
$ Page = $ ys;
// Calculate the record offset
$ Offset = $ pagesize * ($ page-1 );
// Retrieve records
$ Res = mysql_query ("select id, title from main order by id desc limit $ offset, $ pagesize", $ db );
// Display records cyclically
If ($ myrow = mysql_fetch_array ($ res ))
{
$ I = 0;
?>
|
Content |
Do {$ I ++;?>
|
') "> |
}While ($ myrow = mysql_fetch_array ($ res ));Echo"
";
}
// Display the total number of pages
Echo"
Total ". $ pages." page (". $ page."/". $ pages .")
";
// Display the number of pages
For ($ I = 1; $ I <$ page; $ I ++)
Echo "page". $ I ";
Echo "page". $ page ";
For ($ I = $ page + 1; $ I <= $ pages; $ I ++)
Echo "page". $ I ";
Echo"
";
// Display to page number
Echo "";
Echo"
";
?>
The http://www.bkjia.com/PHPjc/318881.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/318881.htmlTechArticle code is as follows :? Php // connect to the database $ db = mysql_connect ("localhost", "root", ""); mysql_select_db ("hy", $ db ); // set the number of records displayed on each page $ pagesize = 25; // retrieve records...