冷敷和分页 [英] Coldfusion and Pagination

查看:96
本文介绍了冷敷和分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我对ColdFusion非常新,但是我学得很快。所以我试图建立一个大型数据库,最初显示所有结果,每页25行,并有一个next / prev链接浏览页面。



这一切都很好,但是当我执行搜索时,当新的结果显示几个页面的价值,分页链接不工作。当我点击下一个链接,它会回到原始的所有记录显示。我如何解决这个问题,或者我需要做什么来使它工作?



对不起,我是新的发布,这是我的第一个。希望这更好。



我的分页代码...

  < cfset Next = StartRow + DisplayRows> 
< cfset上一页= StartRow - DisplayRows>

< cfoutput>
< cfif上一页GTE 1>
< a href =#CGI.Script_Name#?StartRow =#上一页#>< b>上一页#DisplayRows#Records< / b>< / a>
< cfelse>
以前的记录
< / cfif>
< b> | < / b>
< cfif Next lte records.RecordCount>
< a href =#CGI.Script_Name#?StartRow =#Next#>< b> Next
< cfif(records.RecordCount - Next)lt DisplayRows&
#Evalute((records.RecordCount - Next)+1)#
< cfelse>
#DisplayRows#
< / cfif> Records< / b>< / a>
< cfelse>下一条记录
< / cfif>
< cfoutput>

我的代码在顶部...

 < cfparam name =StartRowdefault =1> 
< cfparam name =DisplayRowsdefault =25>

< cfset ToRow = StartRow +(DisplayRows - 1)>
< cfif ToRow gt records.RecordCount>
< cfset ToRow = records.RecordCount>
< / cfif>

如果您需要更多资讯,请与我们联络。谢谢。

解决方案

这里是一个例子,我鞭打了(对不起,如果它是简洁),它涵盖了你已经讨论过的事情与马克。我也喜欢Mark的< cfloop> 示例(下面)。因此,我们有:

ul>
  • 查询记录计数(max)

  • 从您的范围开始

  • $ b
  • 每页输出



  • 使用额外的pageNum查询字符串为您的下一组记录)。



    然后在您的网页中显示如下:

     < cfparam name =pageNumdefault =1> 

    < cfquery name =qdatasource =#application.dsn#>
    select * from yourTable
    < / cfquery>

    < cfset maxRows = 10>
    < cfset startRow = min((NumberNum-1)* maxRows + 1,max(q.recordCount,1))>
    < cfset endRow = min(startRow + maxRows-1,q.recordCount)>
    < cfset totalPages = ceiling(q.recordCount / maxRows)>

    < cfset loopercount = round(q.recordCount / 10)>

    < cfoutput>
    < cfloop from =1to =#looperCount#index =i>
    < a href =?pageNum =#i#>#i#< / a>
    < / cfloop>
    < / cfoutput>

    < br>< br>

    < cfoutput
    query =q
    startrow =#startRow#
    maxrows =#maxRows#>

    #id#< br>

    < / cfoutput>


    First I am very new to ColdFusion, but am learning pretty quickly. So I am trying to build a large database that originally displays all results with 25 lines per page and have a next/prev link to navigate through the pages.

    That all works fine, but when I perform a search, and when the new results display of about a couple of pages worth, the pagination links don't work. When I click on the "next" link it goes back to the original all records display. How can I fix this or what do I need to do to make it work?

    Sorry I'm new at posting and this is my first one. Hope this is better.

    My pagination code...

    <cfset Next = StartRow + DisplayRows>
    <cfset Previous = StartRow - DisplayRows> 
    
    <cfoutput> 
      <cfif Previous GTE 1> 
        <a href="#CGI.Script_Name#?StartRow=#Previous#"><b>Previous #DisplayRows# Records</b></a> 
      <cfelse> 
        Previous Records 
      </cfif> 
      <b> | </b> 
      <cfif Next lte records.RecordCount> 
        <a href="#CGI.Script_Name#?StartRow=#Next#"><b>Next 
        <cfif (records.RecordCount - Next) lt DisplayRows> 
          #Evalute((records.RecordCount - Next)+1)# 
        <cfelse> 
          #DisplayRows# 
        </cfif>Records</b></a>
      <cfelse> Next Records 
      </cfif> 
    <cfoutput>
    

    My code at the top...

    <cfparam name="StartRow" default="1"> 
    <cfparam name="DisplayRows" default="25"> 
    
    <cfset ToRow = StartRow + (DisplayRows - 1)> 
    <cfif ToRow gt records.RecordCount> 
      <cfset ToRow = records.RecordCount> 
    </cfif>
    

    Let me know if you need to see more...thank you.

    解决方案

    Here is an example I whipped up (sorry if it is terse), and it covers things you already discussed with Mark. I also like Mark's <cfloop> examples above (below). Lol...Where ever this response ends up.

    So we have:

    • query recordcount (max)
    • starting in your range
    • ending in your range
    • output per page

    With bonus pageNum querystring for your next grouping of records (which I think is something you would like).

    Then it can look like this in your page:

    <cfparam name="pageNum" default="1">
    
    <cfquery name="q" datasource="#application.dsn#">
        select * from yourTable 
    </cfquery>
    
    <cfset maxRows = 10>
    <cfset startRow = min( ( pageNum-1 ) * maxRows+1, max( q.recordCount,1 ) )>
    <cfset endRow = min( startRow + maxRows-1, q.recordCount )>
    <cfset totalPages = ceiling( q.recordCount/maxRows )>
    
    <cfset loopercount = round( q.recordCount/10 )>
    
    <cfoutput>
        <cfloop from="1" to="#looperCount#" index="i">
                <a href="?pageNum=#i#">#i#</a>
        </cfloop>
    </cfoutput> 
    
    <br><br>
    
    <cfoutput
        query="q" 
        startrow="#startRow#"
        maxrows="#maxRows#">
    
        #id#<br>
    
    </cfoutput>
    

    这篇关于冷敷和分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆