Recommended PHP template technology [Go]_php tutorial

Source: Internet
Author: User
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>















{All Lists}
Member List
Name Gender Age Email
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 ...

  • 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.