smarty实例登陆、显示、分页

时间:2023-03-09 01:11:01
smarty实例登陆、显示、分页

1.先建立登陆页面,登陆页面的PHP文件和HTML文件是分开写的。

先建立一个登陆页的PHP文件,

<?php
include("../init.inc.php");//引入smarty模版
$smarty->display("login.html");//显示的代码

要有一个需要显示的页面就用HTML来写

<h1>登录页面</h1>
<form action="logincl.php" method="post">
<div>用户名:<input type="text" name="uid" /></div>
<div>密码:<input type="password" name="pwd" /></div>
<input type="submit" value="登陆" />
</form>

这两个写完以后就会出现以下的网页效果

smarty实例登陆、显示、分页

建立好之后要对登陆进行处理 在建立一个处理页面把数据传输进来进行处理;

<h1>登录页面</h1>
<form action="logincl.php" method="post">
<div>用户名:<input type="text" name="uid" /></div>
<div>密码:<input type="password" name="pwd" /></div>
<input type="submit" value="登陆" />
</form>
<?php
include("../dbda.class.php");
$db = new dbda();
$uid = $_POST["uid"];
$pwd = $_POST["pwd"];
$sql = "select pwd from users where uid ='{$uid}'";//匹配密码
$mm= $db->strquery($sql);
if($mm == $pwd && !empty($pwd))
{
header("location:main.php");登陆成功后跳转的这个页面。
}

建立一个main.php页面来从数据库中调出来的内容,同时实现分页

<?php
include("../init.inc.php");//引入smarty模版
include("../dbda.class.php");//引进数据库
$db = new dbda();
//分页
$sall="select count(*) from car";
$zts= $db->StrQuery($sall);
include("../page.class.php");
$page = new Page($zts,5);分页的显示条数; $sql = "select * from car ".$page->limit;
$arr = $db->query($sql); $smarty->assign("fenye",$page->fpage());
$smarty->assign("shuju",$arr);把数组导入到smarty模版中
$smarty->display("main.html");调用display来显示模版文件

在建立main.html页面设计要显示的样式;

<h1>主页面</h1>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>代号</td>
<td>名称</td>
<td>操作</td>
</tr> <{foreach $shuju as $v}>//用smarty模版中的foreach来遍历
<tr>
<td><{$v[0]}></td>
<td><{$v[1]}></td>
<td><a href="shanchu.php?code=<{$v[0]}>">删除</a>
<a href="xiugai.php?code=<{$v[0]}>">修改</a> //在这里实现一下修改的功能,建立一个修改的处理页面,把主键值传入到修改页面
</td>
</tr>
<{/foreach}>

<div><{$fenye}></div>建个div来显示分页
</table>

 

smarty实例登陆、显示、分页

<?php
include("../init.inc.php");
include("../dbda.class.php");
$db = new dbda(); $code = $_GET["code"]; $sql = "select * from car where code = '{$code}'";
$arr = $db->query($sql);
$smarty->assign("nation",$arr[0]);注册到smarty模版中 取到以为数组
$smarty->display("xiugai.html");
调用display来显示模版文件

建立一个修改显示页面

<h1>修改页面</h1>
<form action="update.php" method="post">
<div>代号: <input type="text" name="code" value="<{$nation[0]}>" /></div>
<div>名称: <input type="text" name="name" value="<{$nation[1]}>" /></div>
<input type="submit" value="修改" />
</form>

点击修改打开修改的页面点击哪个自动显示需要修改的内容。

smarty实例登陆、显示、分页