php smarty 分页类,Smarty分页类Smartypaginate
不羅嗦了,直接上范例
function.paginate_first.php、function.paginate_last.php、function.paginate_prev.php、function.paginate_next.php、function.paginate_middle.php五個(gè)文件放在Smarty的plugins目錄下,SmartyPaginate.class.php我放在了Smarty的根目錄下,你們可以參考。
PHP程序
require_once 'includes/Smarty/SmartyPaginate.class.php';? //包含分頁(yè)類的類文件
SmartyPaginate::connect(); 連接到分類頁(yè)
SmartyPaginate::setLimit(10); //一頁(yè)取多少條記錄
$smarty->assign('results',get_od_results()); //將要分頁(yè)的數(shù)據(jù)進(jìn)行分割并指定Smarty變量
SmartyPaginate::assign($smarty); // 賦值給Smarty
$smarty->display('scorderform.html'); //smarty模板
函數(shù):
$_query = sprintf("SELECT SQL_CALC_FOUND_ROWS * FROM table ORDER BY id DESC LIMIT %d,%d", SmartyPaginate::getCurrentIndex(), SmartyPaginate::getLimit()); $_result = $GLOBALS['db']->query($_query); while ($_row = $GLOBALS['db']->fetch_array($_result, MYSQL_ASSOC)) { // collect each record into $_data $_data[] = $_row; } // now we get the total number of records from the table $_query1 = "SELECT FOUND_ROWS() as total"; $_result1 = $GLOBALS['db']->query($_query1); $_row = $GLOBALS['db']->fetch_array($_result1, MYSQL_ASSOC); SmartyPaginate::setTotal($_row['total']); return $_data;
說(shuō)明:$GLOBALS['db']是我自己事先用的數(shù)據(jù)庫(kù)類,大家可以舉一反三,使用自己的數(shù)據(jù)庫(kù)類
模板相關(guān)寫(xiě)法
{paginate_first text="第一頁(yè)"}{paginate_prev text="上一頁(yè)"}
{paginate_middle format="page" page_limit="5" link_prefix="" link_suffix="" prefix="" suffix="" class="number current"}
{paginate_next text="下一頁(yè)"} {paginate_last text="末頁(yè)"}
{section name=res loop=$results}
這里循環(huán)你要分頁(yè)的數(shù)據(jù)
{/section}在function.paginate_middle.php中,大約130行左右,將代碼修改成以下
if($_item != $_curr_item) { ????$_this_url = $_url;????$_this_url .= (strpos($_url, '?') === false) ? '?' : '&';????$_this_url .= SmartyPaginate::getUrlVar($_id) . '=' . $_item;????$_ret .= $_link_prefix . '' . $_text . '' . $_link_suffix;} else {????$_ret .= $_link_prefix . '' . $_text . '' . $_link_suffix;}這樣就是在當(dāng)前頁(yè)和非當(dāng)前頁(yè)采用不同的樣式
總結(jié)
以上是生活随笔為你收集整理的php smarty 分页类,Smarty分页类Smartypaginate的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: php作业案例10,5月23日作业——实
- 下一篇: php简单代码大全,征集常用的PHP简单