1。使用Smarty的分页插件,如Pager,pagnition,sliding_page等,不过感觉都不是太好,几乎都有一些Bug。
有兴趣试用和自己去改进的朋友可以看看:
http://smarty.php.net/contribs/plugins/view.php/function.pager.php
http://www.phpinsider.com/smarty-forum/viewtopic.php?t=2327
http://www.phpinsider.com/smarty-forum/viewtopic.php?t=1604
2。使用分页类库,呵呵,这个网上就太多了,一大把,不过我还没有发现写得很好的,特别是容易扩展的。
在搜索的时候还看到一个号称分页类终结者的,哈哈,有点好笑。分页类中把SQL都包含进去了,这个是绝对不能容忍的,可以说作者对OO的认识还比较浅。
不过分页类库不一定适合Smarty,特别是当记录集数据是二维数组时,我不想放弃Smarty方便的Section。这是我没有用PEAR::Pager的原因,否则还要先对数组进行处理,也很麻烦。
3。自己写啦。。我暂时没有选择写成类库,不过改写很容易,下面主要讲讲思路。
其实Smarty的分页非常简单,首先我们可以在模板中这样实现:
{$pager_Links}
{section name="list" loop=$productID start=0 max=$pager_Total step=1}
{if ($smarty.section.list.index >= $pager_StartNum )&& ($smarty.section.list.index 产品名称:{$productName[list]}
产品类别:{$catalogName[list]}
{/if}
{/section}
以上就可以将一个记录集(二维数组)轻松地打印出来,而且限定每页的显示范围。
{$pager_Links} 分页标签(就是上一页,下一页等)
max=$pager_Total 记录总数
$smarty.section.list.index >= $pager_StartNum )&& ($smarty.section.list.index 这一行是用来限定记录的显示范围的,如果记录的索引落在这个范围之内就显示出来,否则就不显示。
以上可以看出,在PHP文件中,我们只需要传递4个变量给Smarty对象:
1.记录总数
2.每页记录起始数
3.每页记录结束数
4.分页标签
以下代码代参考:
标签可以自己去写了,可以扩充成更强大的。现在我没有时间,不然会写一个
$smartyArr = $smarty->get_template_vars();
//记录总数,每页显示记录条数,总页数

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

List操作//从list头部插入一个值。$ret=$redis->lPush('city','guangzhou');//从list尾部插入一个值。$ret=$redis->rPush('city','guangzhou');//获取列表指定区间中的元素。0表示列表第一个元素,-1表示最后一个元素,-2表示倒数第二个元素。$ret=$redis->l

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。

1:JSONArray转ListJSONArray字符串转List//初始化JSONArrayJSONArrayarray=newJSONArray();array.add(0,"a");array.add(1,"b");array.add(2,"c");Listlist=JSONObject.parseArray(array.toJSONString(),String.class);System.out.println(list.to

如何使用C#中的List.Sort函数对列表进行排序在C#编程语言中,我们经常需要对列表进行排序操作。而List类的Sort函数正是为此设计的一个强大工具。本文将介绍如何使用C#中的List.Sort函数对列表进行排序,并提供具体的代码示例,帮助读者更好地理解和应用该函数。List.Sort函数是List类的一个成员函数,用于对列表中的元素进行排序。该函数接

一、List接口简介List是一个有序的集合、可重复的集合。它是继承Collection接口,在List集合中是可以出现重复的元素,可以通过索引(下标)来访问指定位置的元素。二、List常用方法——voidadd(intindex,Obejctelement)方法1.voidadd(intindex,Obejctelement)方法是把element元素插入在指定位置,后面的元素往后移一个元素。2.voidadd(intindex,Obejctelemen

一.最常见方式(未必最佳)通过Arrays.asList(strArray)方式,将数组转换List后,不能对List增删,只能查改,否则抛异常。关键代码:Listlist=Arrays.asList(strArray);privatevoidtestArrayCastToListError(){String[]strArray=newString[2];Listlist=Arrays.asList(strArray);//对转换后的list插入一条数据list.add("1"

示例在这个例子中,我们先看看list.sort()的用法,然后再继续。在这里,我们创建了一个列表并使用sort()方法按升序排序-#CreatingaListmyList=["Jacob","Harry","Mark","Anthony"]#DisplayingtheListprint("List=",myList)#SorttheListsinAscendingOrdermyList.sort(


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
