Template
Site structure
Code:
Site
┗includes
┗class.inc
┣templet
┗index.htm
┣list.htm
┗content.htm
┣index.php
┗content.php
Library structure
Code:
--Database: ' Test '
--The structure of the table ' test '
CREATE TABLE ' Test ' (
' ID ' smallint (3) not NULL auto_increment,
' Name ' varchar ' not NULL default ',
' Sex ' enum (' Male ', ' female ') not NULL default ' male ',
' Age ' smallint (2) Not NULL default ' 0 ',
' Email ' varchar not NULL default ',
PRIMARY KEY (' id ')
) Type=myisam auto_increment=1;
---------------class.inc File--------
[Copy this Code] code:<?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 this Code] Code:<HEAD>
<TITLE> Home </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%> Sex </TD>
<TD width=25%> Age </TD>
<TD width=25%>email</td>
</TR>
{All Lists}
<tr bgcolor= "#ffffff" >
<TD colspan=2> Total {total number of bars} records, display {per page bar/page </TD>
<TD colspan=2 align=right>{Paging}</td>
</TR>
</TABLE>
</BODY>
</HTML>
------------------list.htm File-------------------
[Copy this Code] Code:<tr bgcolor= "#ffffff" align=center>
<td><a href= "content.php?id={member ID}" >{name}</a></td><td>{sex}</td><td>{Age }</td><td>{email}</td>
</TR>
-------------------content.htm File-----------------------
[Copy this Code] Code:<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> Sex </td><td>{Sex}</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 this Code] code:<?php
Include ("Includes/class.inc");
$tmpl =new Templet;
$mycon =new Mycon;
$con = $mycon->connect ();
mysql_select_db ("Test", $con);
$lim = 20; Show number of rows per page
$p = ($_get[p])? $_GET[P]: 1; Current page number
/***** Build list Start *****/
$lists = "";
$tmpl->get_file ("templet/list.htm");
$tags = Array ("Member id", "name", "Gender", "age", "email"); Should be in the same order as a 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);
}
/***** Build list complete, paging start *****/
$tmpl->get_file ("templet/index.htm");
$rn = @mysql_result (mysql_query ("SELECT count (ID) from test"), 0); Total number of records
$ps = Ceil ($rn/$lim); Total pages
$pagination = "<a href= '? p=1 ' > Home </a>";
if ($p >1) $pagination. = "<a href= '? p=". ($p-1). "' > ";
else $pagination. = "<font color= ' #777777 ' >";
$pagination. = "Prev </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 </a>";
/***** pagination complete, build page start *****/
$tags = Array ("All lists", "total number of bars", "per page number", "paging");
$vals = Array ($lists, $rn, $lim, $pagination);
echo $tmpl->parse ($tags, $vals);
?>
----------------content.php File---------------
[Copy this Code] code:<?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]); Remove extra fields that are read out of the table, align replacements, or list fields in a SELECT statement
$tags = Array ("name", "Sex", "age", "email");
echo $tmpl->parse ($tags, $row);
?>