We recommend the php template technology [transfer]. Site Structure code: site metadata describedomainclass.inc?templet=index.htm=list.htm=content.htm metadata index. php metadata content. php database structure Code: -- Database: 'test' -- table structure Site Structure
Code:
Site
Regionregiondes
Category class. inc
┣ Templet
┗Index.htm
┣List.htm
┗Content.htm
Using index. php
Invalid content. php
Database structure
Code:
-- Database: 'test'
-- Table structure 'test'
Create table 'test '(
'Id' smallint (3) not null auto_increment,
'Name' varchar (10) not null default '',
'Sex' enum ('male', 'female ') not null default 'male ',
'Age' smallint (2) not null default '0 ',
'Email 'varchar (20) not null default '',
Primary key ('id ')
) TYPE = MyISAM AUTO_INCREMENT = 1;
--------------- Class. inc file --------
The code is as follows:
Class mycon {
Private $ myhost;
Private $ myuser;
Private $ mypwd;
Function mycon ($ host = "localhost", $ user = "root", $ pwd = ""){
$ This-> myhost = $ host;
$ This-> myuser = $ user;
$ This-> mypwd = $ pwd;
}
Function connect (){
Return mysql_connect ($ this-> myhost, $ this-> myuser, $ this-> mypwd );
}
}
Class templet {
Private $ source_file;
Function get_file ($ filename ){
$ This-> source_file = file_get_contents ($ filename );
}
Function parse ($ tags, $ vals ){
If (! Is_array ($ tags )){
Return preg_replace ("| {". $ tags. "} |", $ vals, $ this-> source_file );
} Else {
$ An = count ($ tags );
For ($ I = 0; $ I <$ an; $ I ++ ){
$ Tags [$ I] = "| {". $ tags [$ I]. "} | ";
}
Return preg_replace ($ tags, $ vals, $ this-> source_file );
}
}
}
?>
----------------Index.htm file -------------------
The code is as follows:
Homepage
Member list
Name |
Gender |
Age |
Email |
{All lists}
A total of {total number} records are displayed. {number of entries per page} Records/page |
{Pagination} |
------------------List.htm file -------------------
The code is as follows:
{Name}{Gender}{Age}{Email}
-------------------Content.htm file -----------------------
The code is as follows:
Member Information
Member Information
Name |
{Name} |
Gender |
{Gender} |
Age |
{Age} |
Email |
{Email} |
---------------- Index. php file --------------------------
The code is as follows:
Include ("includes/class. inc ");
$ Tmpl = new templet;
$ Mycon = new mycon;
$ Con = $ mycon-> connect ();
Mysql_select_db ("test", $ con );
$ Lim = 20; // number of lines per page
$ P = ($ _ GET [p])? $ _ GET [p]: 1; // Current page number
/***** Start to generate the list *****/
$ Lists = "";
$ Tmpl-> get_file ("templet/list.htm ");
$ Tags = array ("member ID", "name", "gender", "age", "email"); // it should be in the same order as the table field
$ Rs = mysql_query ("select * from test order by id desc limit". ($ P-1) * $ lim. ", $ lim ");
While ($ row = mysql_fetch_row ($ rs )){
$ Lists. = $ tmpl-> parse ($ tags, $ row );
}
/***** The list is generated, and the page starts *****/
$ Tmpl-> get_file ("templet/index.htm ");
$ Rn = @ mysql_result (mysql_query ("select count (id) from test"), 0); // The total number of records
$ Ps = ceil ($ rn/$ lim); // total number of pages
$ Pagination = "homepage ";
If ($ p> 1) $ pagination. = "";
Else $ pagination. = "";
$ Pagination. = "previous page ";
If ($ p <$ ps) $ pagination. = "";
Else $ pagination. = "";
$ Pagination. = "Last page of the next page ";
/***** The page is complete, and the page generation starts *****/
$ Tags = array ("all lists", "Total number of entries", "number of entries per page", "pagination ");
$ Vals = array ($ lists, $ rn, $ lim, $ pagination );
Echo $ tmpl-> parse ($ tags, $ vals );
?>
---------------- Content. php file ---------------
The code is as follows:
Include ("includes/class. inc ");
$ Tmpl = new templet;
$ Mycon = new mycon;
$ Con = $ mycon-> connect ();
Mysql_select_db ("test", $ con );
$ Tmpl-> get_file ("templet/content.htm ");
$ Rs = mysql_query ("select * from test where id = $ _ GET [id]");
$ Row = @ mysql_fetch_row ($ rs );
Unset ($ row [0]); // removes unnecessary fields read from the table, alignment and replacement items, or lists fields in the SELECT statement.
$ Tags = array ("name", "gender", "age", "email ");
Echo $ tmpl-> parse ($ tags, $ row );
?>
Repository code: The site uses includes into class. inc uses templet into index.htm into list.htm into content.htm into index. php contains content. php library structure Code: -- Database: 'test' -- table structure...