一聚教程网:一个值得你收藏的教程网站

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

mg电子:虽然网络舆论场对今年两会期间有关个税改革的话题存在诸多声音,其中不乏有负面的言论和观点,但是大多数网民对我国个税改革仍表示充满了信心和期待,他们表示,我国个税改革虽困难重重,但可逐渐完善,期待有关部门尽早将改革共识转化为实际行动。

时间:2008-02-20 00:00:00 编辑:简简单单 来源:转载

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.bjxdzj.com/mgdz/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`)
)

文章评论

热门栏目

合作: 体育博彩 永利注册 mg电子