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

热门教程

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

时间:2022-07-02 10:49:50 编辑:袖梨 来源:一聚教程网

smarty的设置

;/********

[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

http://www.w3.org/1999/xhtml">



guestbook



{{foreach from = $rs item = item}}
 
   
   
 
{{/foreach}}
 
       
 
{{$item.name}}:{{$item.content}}

        一共有{{$pages}}页
        {{$total}}条数据
        每页显示{{$rows}}条
        上翻
        {{foreach from = $links item = num}}
        {{if $num == $current_page}}
                {{$num}}
        {{else}}
                {{$num}}
        {{/if}}
        {{/foreach}}
        下翻
       



 
   
   
 
 
   
   
 
 
         
 

用户名
内容


 下面是显示程序
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');
?>

下面是保存留言代码
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`)
)

热门栏目