Home > Backend Development > PHP Tutorial > Recommended php template technology [transfer]_PHP tutorial

Recommended php template technology [transfer]_PHP tutorial

WBOY
Release: 2016-07-21 15:58:02
Original
1970 people have browsed it

Site structure

Code:
site
┗includes
┗class.inc
┣templet
┗index.htm
┗content .htm
┣index.php
┗content.php
Library 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 code 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 template{
private $source_file;
function get_file($filename){
$ this->source_file = file_get_contents($filename);                                                                                           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 code

The code is as follows:


Homepage
>

/caption>                                                                                                                                                                             > {All lists}

/TD>                                                             >




------------------list.htm file------- ------------



Copy code

The code is as follows:

   🎜>------------------content.htm file-----------------------



Copy code
The code is as follows: TITLE> =#000000 style="font-size:12px">                                                        60>Name
     
   
                                                                                       ;
{name}{gender} {age}{email}{Name}
Gender {Age}





------------- ---index.php file--------------------------
Copy code 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 rows displayed per page
$p = ($_GET[p]) ? $_GET[p ] : 1; //Current page number

/***** Start generating list *****/

$lists = "";
$tmpl->get_file("templet/list. htm");
$tags = array("Member ID", "Name", "Gender", "Age", "email"); // Should be in the same order as the 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);
}

/***** List generation completed, paging begins *****/

$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 number of pages
$pagination = "Homepage ";
if($p>1) $pagination .= "< a href='?p=".($p-1)."'>";
else $pagination .= "";
$pagination . = "Previous page
"; "
if($p<$ps) $pagination .= "";  
else $pagination .= "";
Last page "; "

/***** Pagination completed, page generation begins *****/ ","Total number of items","Number of items per page","Paging"); 
 $vals = array($lists,$rn,$lim,$pagination); 
 echo $tmpl-> parse($tags,$vals);
?>



---------------- content.php file ---------------


Copy code 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]); //Remove redundant fields read from the table, align replacements, or list fields in the SELECT statement
$tags = array("name", "gender", "age", "email");
echo $tmpl->parse($tags,$row);
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/317637.htmlTechArticleSite structure code: Site┗includes ┗class.inc ┣templet ┗index.htm ┣list.htm ┗content. htm ┣index.php ┗content.php Library structure code: --Database:`test` --Table structure...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template