This article mainly introduces the file display of smarty in php. Interested friends can refer to it. I hope it will be helpful to everyone.
First make a simple form
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <form action="insert.php" method="post" enctype="multipart/form-data"> <center> <table> <tr> <td>账号</td> <td><input type="text" name="aa"></td> </tr> <tr> <td>密码</td> <td><input type="text" name="bb"></td> </tr> <tr> <td>文件</td> <td><input type="file" name="img"></td> </tr> <tr> <td><input type="submit" value="添加"></td> </tr> </table> </center> </form> </body> </html>
Add jump to the add page
<?php header("content-type:text/html;charset=utf-8");include ("./DB.class.php"); //引入自己的增删改查封装并且进行文件移动$d= new DB("127.0.0.1","root","root","user"); //实例化入库选库 并传参$p3=new SC(); //实例化添加类 $res=$p3->say($_POST,$_FILES,'img',"images/",'image'); //1参数为上传的文本信息,2参数为上传图片信息, 3 参数为图片的name名,4参数为移动文件目录,5参 数为添加到的数据表。 if ($res) {echo "<script>alert('上传成功');location.href='index.php'</script>";//成功则自动跳转查询页面}else{echo "<script>alert('上传失败');location.href='form.php'</script>";//失败则自动跳转form表单} ?>
Query page
<?php header("content-type:text/html;charset=utf-8"); include ("./DB.class.php"); //引入文件 $d= new DB("127.0.0.1","root","root","user"); $p7=new F; //实例化类 $aa=isset($_GET['aa'])?$_GET['aa']:""; //三元运算符进行判断页数是否为空 $data=$p7->say('bb','2',$aa); //三个值分别为表名 分页每页的个数 和查询的值 $shang=$p7->shang; //获取上一页的变量 $xia=$p7->xia; //获取下一页的变量 $wei=$p7->wei; //获取尾wei页的变量 include ("libs/Smarty.class.php"); //引入Smarty文件 $ok = new Smarty; $ok->assign("aa",$aa); $ok->assign("shang",$shang); $ok->assign("xia",$xia); $ok->assign("wei",$wei); $ok->assign("list",$data); //指向并赋值 $ok->display("show.php"); //指向的页面 ?>
Display and search page
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>展示</title> </head> <body> <form action="index.php" method="get"> <table> <tr> <td colspan="2" align="center"><input type="text" name="aa"><input type="submit" value="搜索"></td> </tr> <tr> <td>id</td> <td>name</td> <td>pwd</td> <td>img</td> </tr> {section loop=$list name=l} <tr> <td>{$list[l].id}</td> <td>{$list[l].aa}</td> <td>{$list[l].bb}</td> <td><img src="{$list[l].img}" alt="" height="50" width="60"> </td> {if {$list[l].ll} eq 1} <td><a href="up.php?id={$list[l].id}&ll=0">上架</a></td> {else} <td><a href="up.php?id={$list[l].id}&ll=1">下架</a></td> {/if} <td><a href="del.php?id={$list[l].id}">删除</a></td> </tr> {/section} <tr> <td><a href="index.php?page=1&aa={$aa}">首页</a></td> <td><a href="index.php?page={$shang}&aa={$aa}">上一页</a></td> <td><a href="index.php?page={$xia}&aa={$aa}">下一页</a></td> <td><a href="index.php?page={$wei}&aa={$aa}">为页</a></td> </tr> </table> </form> </body> </html>
Related recommendations:
More complete notes on Smarty in PHP
Configuration file data and retained data of smarty template engine
Smarty built-in in PHP Detailed explanation of function include
The above is the detailed content of Smarty file display in php. For more information, please follow other related articles on the PHP Chinese website!