<cfquery name="gb1" datasource="gbook">
select * from gbook order by id desc
</cfquery>
<!---定义分页变量--->
<cfset maxrows="5">
<cfparam name="url.startrow" default="1">
<cfif #url.startrow# is not "1">
<cfset UpRow=#url.startrow#-#maxrows#>
<cfelse>
<cfset UpRow="1">
</cfif>
<cfset DownRow=#url.startrow#+#maxrows#>
<cfif #DownRow# gt #gb1.recordcount#>
<cfset DownRow="#url.startrow#">
</cfif>
<cfif (#gb1.recordcount# mod #maxrows#) is 0>
<cfset lastrow=#gb1.recordcount#-#maxrows#+1>
<cfelse>
<cfset lastrow=(#gb1.recordcount#\#maxrows#)*#maxrows#+1>
</cfif>
<!---定义分页变量结束--->
<table border="1">
<tr>
<td>姓名</td>
<td>电子邮件</td>
<td>QQ号码</td>
<td>个人主页</td>
<td>留言内容</td>
<td>用户IP</td>
<td>留言日期</td>
</tr>
<cfoutput query="gb1" startrow="#url.startrow#" maxrows="#maxrows#">
<tr>
<td>#gb1.name#</td>
<td>#gb1.email#</td>
<td>#gb1.qq#</td>
<td>#gb1.homepage#</td>
<td>#gb1.content#</td>
<td>#gb1.ip#</td>
<td>#gb1.riqi#</td>
</tr>
</cfoutput>
</table>
<cfoutput>
<!---开始分页--->
<p align=left>
<input type=button value="第一页" class=btn onclick="javascript:location.href='main.cfm';">
<input type=button value="上一页" class=btn onclick="javascript:location.href='main.cfm?startrow=#uprow#';">
<input type=button value="下一页" class=btn onclick="javascript:location.href='main.cfm?startrow=#downrow#';">
<input type=button value="最后页" class=btn onclick="javascript:location.href='main.cfm?startrow=#lastrow#';">
</p>
<!---分页结束--->
</cfoutput>
示例:
图片如下: