Php development page implementation code. For more information about php learning, see
Php development page implementation code. For more information about php learning, see
Conn. php
The Code is as follows:
$ Conn = @ mysql_connect ("localhost", "root", "") or die ("Database Link error ");
Mysql_select_db ("form", $ conn );
Mysql_query ("set names 'gbk'"); // use GBK Chinese encoding;
// Replace spaces and enter the Enter key
Function htmtocode ($ content ){
$ Content = str_replace ("\ n ","
", Str_replace (" "," ", $ content ));
Return $ content;
}
?>
Page. php
The Code is as follows:
1 2
3 function _ PAGEFT ($ totle, $ displaypg = 20, $ url = ''){
4
5 global $ page, $ firstcount, $ pagenav, $ _ SERVER;
6
7 $ GLOBALS ["displaypg"] = $ displaypg;
8
9 if (! $ Page)
$ Page = 1;
If (! $ Url ){
$ Url = $ _ SERVER ["REQUEST_URI"];
}
// URL analysis:
$ Parse_url = parse_url ($ url );
$ Url_query = $ parse_url ["query"]; // retrieve the query string of the URL separately.
If ($ url_query ){
$ Url_query = ereg_replace ("(^ | &) page = $ page", "", $ url_query );
$ Url = str_replace ($ parse_url ["query"], $ url_query, $ url );
If ($ url_query)
$ Url. = "& page ";
Else
$ Url. = "page ";
} Else {
$ Url. = "? Page ";
}
$ Lastpg = ceil ($ totle/$ displaypg); // The last page, also the total number of pages
$ Page = min ($ lastpg, $ page );
$ Prepg = $ page-1; // Previous page
$ Nextpg = ($ page = $ lastpg? 0: $ page + 1); // next page
$ Firstcount = ($ page-1) * $ displaypg;
// Start the paging navigation bar code:
$ Pagenav = "display
". ($ Totle? ($ Firstcount + 1): 0 )."-
". Min ($ firstcount + $ displaypg, $ totle )."A total of $ totle records ";
// If there is only one page, the function will jump out:
If ($ lastpg <= 1)
Return false;
$ Pagenav. = "Homepage ";
If ($ prepg)
$ Pagenav. = "front page ";
Else
$ Pagenav. = "front page ";
If ($ nextpg)
$ Pagenav. = "";
Else
$ Pagenav. = "";
$ Pagenav. = "last page ";
// Pull-down Jump list, listing all page numbers cyclically:
$ Pagenav. =" \ N ";For ($ I = 1; $ I <= $ lastpg; $ I ++ ){If ($ I = $ page)$ Pagenav. ="$ I\ N ";Else$ Pagenav. ="$ I\ N ";}$ Pagenav. ="Page, total $ lastpg page ";
}
Include ("conn. php ");
$ Result = mysql_query ("SELECT * FROM 'test '");
$ Total = mysql_num_rows ($ result );
// Call pageft () to display 10 messages per page (this parameter can be omitted when the default value is 20). Use the URL on this page (which is omitted by default ).
_ PAGEFT ($ total, 5 );
Echo $ pagenav;
$ Result = mysql_query ("SELECT * FROM 'test' limit $ firstcount, $ displaypg ");
While ($ row = mysql_fetch_array ($ result )){
Echo"
". $ Row [name]." | ". $ row [sex];
}
?>
List. php
[Code]
Include ("conn. php ");
$ Pagesize = 5;
$ Url = $ _ SERVER ["REQUEST_URI"];
$ Url = parse_url ($ url );
$ Url = $ url [path];
$ Numq = mysql_query ("SELECT * FROM 'test '");
$ Num = mysql_num_rows ($ numq );
If ($ _ GET