首页 > 代码库 > smarty实例

smarty实例

login.php代码

<?php
include("../init.inc.php");

$smarty->display("login.html");

login.html代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<h1>登陆页面</h1>
<form action="loginchuli.php" method="post">
<div>用户名:<input type="text" name="uid" /></div>
<div>密码:<input type="password" name="pwd" /></div>
<div ><input type="submit" value="http://www.mamicode.com/登陆" /></div>
</form>
<body>
</body>
</html>

效果:

技术分享

loginchuli.php 代码

<?php

include("../DBDA.class.php");
$db=new DBDA();
$uid=$_POST["uid"];
$pwd=$_POST["pwd"];
$sql="select pwd from user where uid=‘{$uid}‘";
$mm=$db->StrQuery($sql);
if($pwd=$mm && !empty($pwd))
{
header("location:main.php");
}

main.php 代码

<?php
include("../init.inc.php");
include("../DBDA.class.php");
$db=new DBDA();
$tj=" 1=1 ";
if(!empty($_GET["name"]))
{ $n=$_GET["name"];
$tj="name like‘%{$n}%‘";
}
$ztj=" where {$tj} ";
$sall=" select count(*) from course ".$ztj;
$zts=$db->StrQuery($sall);
include("../page.class.php");
$page=new Page($zts,5);

$sql=" select * from course ".$ztj.$page->limit;
$arr=$db->Query($sql);
$smarty->assign("fenye",$page->fpage());
$smarty->assign("shuzu",$arr);
$smarty->display("main.html");

main.html代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<h1>显示页面</h1>
<form action="main.php" method="get">
<div><input type="text" name="name" />
<input type="submit" value="http://www.mamicode.com/查找" />
</div>
</form>
<table width="100%" cellpadding="0px" cellspacing="0px" border="1px">
<tr>
<td>代号</td>
<td>课程</td>
<td>类型</td>
<td>操作</td>


</tr>
<{foreach $shuzu as $v}>

<tr>
<td><{$v[0]}></td>
<td><{$v[1]}></td>
<td><{$v[2]}></td>
<td><a href="http://www.mamicode.com/xiugai.php?code=<{$v[0]}>">修改</a></td>


</tr>
<{/foreach}>
</table>
<div><{$fenye}></div>

</body>
</html>

 

 

效果:

技术分享

xiugai.php

<?php
include("../init.inc.php");
include("../DBDA.class.php");
$db=new DBDA();
$code=$_GET["code"];
$sql="select * from course where code=‘{$code}‘";
$arr=$db->Query($sql);
$smarty->assign("course",$arr[0]);
$smarty->display("xiugai.html");

 

xiugai.html代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<h1>修改页面</h1>
<form action="update.php" method="post">
<div>代号:<input type="text" name="code" value="http://www.mamicode.com/<{$course[0]}>" /></div>
<div>课程:<input type="text" name="course" value="http://www.mamicode.com/<{$course[1]}>" /></div>
<div>类型:<input type="text" name="type" value="http://www.mamicode.com/<{$course[2]}>"/></div>
<input type="submit" value="http://www.mamicode.com/修改" />
</form>
</body>
</html>

效果

技术分享

 

smarty实例