zoukankan      html  css  js  c++  java
  • 用smarty模板实现数据的显示修改以及分页

    首先根据规则将需要的php和html文件放到相应的文件夹下

    php文件

    <?php
    include("../init.inc.php");
    include("../abc.php");
    $db = new DBDA();
    
    $sql = "select * from nation";
    $arr = $db->Query($sql);
    
    $smarty->assign("shuju",$arr);
    $smarty->display("main.html");

    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>
    
    <table width="100%" border="1" cellpadding="0" cellspacing="0">
    
    <tr>
    <td>代号</td>
    <td>名称</td>
    <td>操作</td>
    
    </tr>
    <{foreach $shuju as $v}>
    <tr>
    <td><{$v[0]}></td>
    <td><{$v[1]}></td>
    <td>操作</td>
    
    </tr>
    <{/foreach}>
    
    </table>
    
    </body>
    </html>

    完成以上两步页面数据显示成功

    然后做修改代码如下

    <tr>
    <td>名称</td>
    <td>操作</td>
    </tr>
    
    <{foreach $shuju as $v}>
    <tr>
    <td><{$v[0]}></td>
    <td><{$v[1]}></td>
    <td><a href="xiugai.php?code=<{$v[0]}>">修改</a></td>
    </tr>
    <{/foreach}>
    (光标移不出去了 就在这里面继续写吧)





    修改页面是需要独立显示出来的 所以也需要php 和 html

    xiugai.php
    <?php
    include("../init.inc.php");
    include("../abc.php");
    $db = new abc();
    
    $code= $_GET["code"];
    
    $sql = "select * from nation where code='{$code}'";
    $arr= $db->Query($sql);
    
    $smarty->assign("nation",$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="<{$nation[0]}>" /></div>
    <div>名称:<input type="text" name="name" value="<{$nation[1]}>" /></div>
    <input type="submit" value="修改" />
    
    </form>
    
    </body>
    </html>

    这样就基本结束了修改的代码

    为了用户体验 需要做一个分页查询

    <?php
    include("../init.inc.php");
    include("../abc.php");
    $db = new abc();
    $sall="select count(*) from nation";
    $zts=$db->StrQuery($sall);
    
    include("../page.class.php");
    $page = new Page($zts,5);
    
    
    $sql = "select * from nation ".$page->limit;//注意 这里有一个空格 没有的话会报错
    $arr = $db->Query($sql);
    
    $smarty->assign("fenye",$page->fpage());
    $smarty->assign("shuju",$arr);
    $smarty->display("main.html");

    在显示的html页面中嵌入<div><{$fenye}></div>

    添加一个查询功能 

    查询代码

    <?php
    include("../init.inc.php");
    include("../abc.php");
    $db = new abc();
    
    $tj = " 1=1 ";
    if(!empty($_GET["name"]))
    {  
        $n = $_GET["name"];
       $tj = " name like '%{$n}%' ";
    }
    
    $ztj= "where {$tj}";
    $sall="select count(*) from nation ".$ztj;
    $zts=$db->StrQuery($sall);
    
    
    
    include("../page.class.php");
    $page = new Page($zts,5);
    
    
    $sql = "select * from nation ".$ztj.$page->limit;
    $arr = $db->Query($sql);
    
    $smarty->assign("fenye",$page->fpage());
    $smarty->assign("shuju",$arr);
    $smarty->display("main.html");

    基本运行成功

  • 相关阅读:
    heapq of python
    array of python
    Unittest of Python
    事件驱动型工作流 vs 引擎型工作流
    airflow
    WPF 调试触发器
    WPF 使用Popup和TreeView实现树状下拉框
    Oracle : ORA 00933: SQL command not properly ended
    PostgreSQL && PostGIS
    基于ArcGIS开发3D立方体空间关系判断
  • 原文地址:https://www.cnblogs.com/xiaoming-6/p/6517197.html
Copyright © 2011-2022 走看看