$ Localhost = "localhost "; $ Username = "root "; $ Password = "root "; $ Db = "test"; // information $ Pagesize = 5; $ Conn = mysql_connect ($ localhost, $ username, $ password); // link to the database If (! $ Conn ){ Echo "database connection failed". mysql_error (); } Mysql_query ("set names 'utf8'"); // Encode and convert $ Db_select = mysql_select_db ($ db); // select a table // Query the total number of records $ Total_ SQL = "select COUNT (*) from page "; $ Total_result = mysql_query ($ total_ SQL ); $ Total_row_arr = mysql_fetch_row ($ total_result ); $ Total_row = $ total_row_arr [0]; // The total number of items. // Total number of pages $ Total = ceil ($ total_row/$ pagesize ); // Current page number $ Page = @ $ _ GET ['P']? $ _ GET ['P']: 1; // Lower limit of limit $ Offset = ($ page-1) * $ pagesize; $ SQL = "select * from page order by id limit {$ offset}, {$ pagesize }"; $ Result = mysql_query ($ SQL ); Echo" Small module of PHP paging code "; Echo" Echo" While ($ row = mysql_fetch_assoc ($ result )){ $ Id = $ row ['id']; $ Name = $ row ['name']; Echo" } Echo"
";
ID |
NAME |
";
". $ Id ." |
". $ Name ." |
";
"; // Previous and next pages $ Pageprev = $ page-1; If ($ page> $ total ){ $ Pagenext = $ total; } Else { $ Pagenext = $ page + 1; } // Perform Link jump; Echo "previous Page Previous Page "; Mysql_free_result ($ result ); Mysql_close ($ conn ); ?> |