Php Development page implementation code page 1/3 _ PHP Tutorial

Source: Internet
Author: User
Php Development page implementation code 13th page. Project structure: running effect: the conn. php copy code is as follows :? Php $ conn @ mysql_connect (localhost, root,) ordie (Database link error); mysql_select_db (form, $ Project structure:

Running effect:

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

Running result: the conn. php code is as follows :? Php $ conn = @ mysql_connect ("localhost", "root", "") or die ("database link error"); mysql_select_db ("form", $...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.