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 --------
Copy codeThe Code is as follows: <? Php
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 -------------------
Copy codeThe Code is as follows: <HTML>
<HEAD>
<TITLE> homepage </TITLE>
</HEAD>
<BODY style = "font-size: 12px">
<Table width = "100%" CELLPADDING = "0" CELLSPACING = "1" bgcolor = #000000 style = "font-size: 12px">
<Caption> member list </caption>
<TR bgcolor = "# ffffff" align = center>
<TD width = 25%> name </TD>
<TD width = 25%> gender </TD>
<TD width = 25%> age </TD>
<TD width = 25%> email </TD>
</TR>
{All lists}
<TR bgcolor = "# ffffff">
<TD colspan = 2> A total of {total number} records are displayed. {number of entries per page} records/page </TD>
<TD colspan = 2 align = right> {pagination} </TD>
</TR>
</TABLE>
</BODY>
</HTML>
------------------List.htm file -------------------
Copy codeThe Code is as follows: <TR bgcolor = "# ffffff" align = center>
<TD> <a href = "content. php? Id = {member ID} ">{ name} </a> </TD> <TD >{ gender} </TD> <TD >{ age} </TD> <TD> {email} </TD>
</TR>
-------------------Content.htm file -----------------------
Copy codeThe Code is as follows: <HTML>
<HEAD>
<TITLE> member information </TITLE>
</HEAD>
<BODY style = "font-size: 12px">
<Table width = "100%" CELLPADDING = "0" CELLSPACING = "1" bgcolor = #000000 style = "font-size: 12px">
<Caption> member information </caption>
<TR bgcolor = "# ffffff">
<TD width = 60> name </TD> <TD >{name} </TD> </TR>
<TR bgcolor = "# ffffff">
<TD> gender </TD> <TD> {gender} </TD> </TR>
<TR bgcolor = "# ffffff">
<TD> age </TD> <TD >{age} </TD> </TR>
<TR bgcolor = "# ffffff">
<TD> email </TD> <TD> {email} </TD> </TR>
</TABLE>
</BODY>
---------------- Index. php file --------------------------
Copy codeThe Code is as follows: <? Php
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 = "<a href = '? P = 1'> homepage </a> ";
If ($ p> 1) $ pagination. = "<a href = '? P = ". ($ P-1)." '> ";
Else $ pagination. = "<font color = '#777777'> ";
$ Pagination. = "Previous Page </font> </a> ";
If ($ p <$ ps) $ pagination. = "<a href = '? P = ". ($ p + 1)." '> ";
Else $ pagination. = "<font color = '#777777'> ";
$ Pagination. = "next page </font> </a> <a href = '? P = {$ ps} '> last page </a> ";
/***** 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 ---------------
Copy codeThe Code is as follows: <? Php
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 );
?>