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">
{{$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`)
)