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 (TEN) Not NULL default ' ',
' Sex ' enum (' Male ', ' female ') not NULL default ' male ',
' Age ' smallint (2) is not NULL default ' 0 ',
' Email ' varchar (not NULL default '),
PRIMARY KEY (' id ')
) Type=myisam auto_increment=1;
---------------class.inc File--------
Copy CodeThe 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-------------------
Copy CodeThe code is as follows:
<title>Home</title>
Member List
| Name |
Gender |
Age |
Email |
{All Lists}
| Total {Total number of entries} record, display {per page count} Bar/page |
{Paging} |
------------------list.htm File-------------------
Copy CodeThe code is as follows:
NameGenderAge{Email}
-------------------content.htm File-----------------------
Copy CodeThe code is as follows:
<title>Member Information</title>
Member Information
| Name |
Name |
| Gender |
Gender |
| Age |
Age |
| Email |
{Email} |
----------------index.php File--------------------------
Copy CodeThe 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 rows displayed per page
$p = ($_get[p])? $_GET[P]: 1; Current page number
/***** Generate list Start *****/
$lists = "";
$tmpl->get_file ("templet/list.htm");
$tags = Array ("Member id", "name", "Gender", "age", "email"); Should be in the same order as table fields
$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 begins *****/
$tmpl->get_file ("templet/index.htm");
$rn = @mysql_result (mysql_query ("SELECT count (ID) from test"), 0); Total Record Count
$ps = Ceil ($rn/$lim); Total pages
$pagination = "Home";
if ($p >1) $pagination. = "";
else $pagination. = "";
$pagination. = "Previous page";
if ($p < $ps) $pagination. = "";
else $pagination. = "";
$pagination. = "Next Page last";
/***** page completion, generation of pages start *****/
$tags = Array ("All lists", "total number of bars", "Number of bars per page", "pagination");
$vals = Array ($lists, $rn, $lim, $pagination);
echo $tmpl->parse ($tags, $vals);
?>
----------------content.php File---------------
Copy CodeThe 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]); Remove extra fields that are read out of the table, align replacements, or list fields in the SELECT statement
$tags = Array ("name", "Gender", "age", "email");
echo $tmpl->parse ($tags, $row);
?>
http://www.bkjia.com/PHPjc/317637.html www.bkjia.com true http://www.bkjia.com/PHPjc/317637.html techarticle site Structure code: Site ┗includes┗class.inc┣templet┗index.htm┣list.htm┗content.htm┣index.php┗content.php Library Structure code:--Database: ' tes T '-the structure of the table ...