Smarty file display in php

墨辰丷
Release: 2023-03-25 19:50:02
Original
1816 people have browsed it

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>
Copy after login


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,&#39;img&#39;,"images/",&#39;image&#39;);                   //1参数为上传的文本信息,2参数为上传图片信息,                                                                                                                   3 参数为图片的name名,4参数为移动文件目录,5参             
                                                                                                         数为添加到的数据表。
if ($res) {echo "<script>alert(&#39;上传成功&#39;);location.href=&#39;index.php&#39;</script>";//成功则自动跳转查询页面}else{echo "<script>alert(&#39;上传失败&#39;);location.href=&#39;form.php&#39;</script>";//失败则自动跳转form表单}
 ?>
Copy after login

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[&#39;aa&#39;])?$_GET[&#39;aa&#39;]:"";     //三元运算符进行判断页数是否为空
$data=$p7->say(&#39;bb&#39;,&#39;2&#39;,$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");      
 //指向的页面
?>
Copy after login

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>
Copy after login

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!

Related labels:
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