教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 smarty 简单留板 分页、静态、缓存等功能的用法

smarty 简单留板 分页、静态、缓存等功能的用法

发布时间:2023-05-11   编辑:jiaochengji.com
教程集为您提供smarty 简单留板 分页、静态、缓存等功能的用法等资源,欢迎您收藏本站,我们将为您提供最新的smarty 简单留板 分页、静态、缓存等功能的用法资源

smarty的设置

<?php
;/********

[database]
hostname = localhost
username = root
password = 123456
dbname = tbb

[html]
web_path = http://localhost

caching = false
compile_check = true
cache_dir = /smarty_file/cache
compile_dir = /smarty_file/compile
template_dir = /smarty_file/template
;*/
;?>

index.htm

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<title>guestbook</title>
</head>

<body>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
{{foreach from = $rs item = item}}
  <tr>
    <td width="20%" align="right">{{$item.name}}:</td>
    <td>{{$item.content}}</td>
  </tr>
{{/foreach}}
  <tr>
        <td colspan="2" align="center">
        一共有{{$pages}}页
        {{$total}}条数据
        每页显示{{$rows}}条
        <a href="{{$web_path}}test.php?page={{$prve}}">上翻</a>
        {{foreach from = $links item = num}}
        {{if $num == $current_page}}
                <b>{{$num}}</b>
        {{else}}
                <a href="{{$web_path}}test.php?page={{$num}}">{{$num}}</a>
        {{/if}}
        {{/foreach}}
        <a href="{{$web_path}}test.php?page={{$next}}">下翻</a>
        </td>
  </tr>
</table>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<form action="add.php" method="POST">
  <tr>
    <td width="20%" align="right">用户名</td>
    <td><input type="text" name="username" style="width:400px"></td>
  </tr>
  <tr>
    <td align="right">内容</td>
    <td><textarea name="content" style="width:400px; height:200px"></textarea></td>
  </tr>
  <tr>
          <td align="center" colspan="2"><input type="submit" name="submit" value=" 提 交 "></td>
  </tr>
</form>
</table>
</body>
</html>

 下面是显示程序
<?php
define('ROOT_PATH', dirname(__FILE__));

require_once ROOT_PATH . '/lib/m_html.class.php';
require_once ROOT_PATH . '/lib/m_db.class.php';
$page = $_GET['page'];

$mdb = new m_db();
$html = new m_html('/test_' . $page . '.html', 30);

$num = $mdb->fetch_one('select count(*) as num from test');
$page_arr = $mdb->page($num['num'], $page, 7, 4);

$rs = $mdb->fetch_all('select * from test order by id desc limit ' . $page_arr['start'] . ',' . $page_arr['rows']);

$html->assign('rs', $rs);
$html->assign('web_path', $html->config['web_path'] . '/');
$html->assign($page_arr);
$html->render('index.htm', '/test_' . $page_arr['current_page'] . '.html');
?>

下面是保存留言代码
<?php
define('ROOT_PATH', dirname(__FILE__));

require_once ROOT_PATH . '/lib/m_db.class.php';
require_once ROOT_PATH . '/lib/m_string.class.php';

$_POST = m_string::addslashes($_POST);
$mdb = new m_db();
$mdb->add('test', array('name', 'content'), array($_POST['username'], $_POST['content']));

header('location:test.php');
?>

CREATE TABLE `test` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `name` varchar(255) NOT NULL,
  `content` tinytext NOT NULL,
  PRIMARY KEY  (`id`)
)

您可能感兴趣的文章:

[关闭]
~ ~