Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql coldfusion分页(下一个和上一个)_Mysql_Pagination_Coldfusion_Railo_Lucee - Fatal编程技术网

Mysql coldfusion分页(下一个和上一个)

Mysql coldfusion分页(下一个和上一个),mysql,pagination,coldfusion,railo,lucee,Mysql,Pagination,Coldfusion,Railo,Lucee,我必须在我的项目中进行分页: 下面的代码运行良好,只是我不知道如何处理下一个/上一个按钮。我在使用mysql数据库 如果您能给我一些最佳实践技巧,那将是非常有帮助的 有没有其他简单的方法?请给我参考,这将是很大的帮助 这是我的密码: <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" type="application/javascript"></script>

我必须在我的项目中进行分页:

下面的代码运行良好,只是我不知道如何处理下一个/上一个按钮。我在使用mysql数据库 如果您能给我一些最佳实践技巧,那将是非常有帮助的 有没有其他简单的方法?请给我参考,这将是很大的帮助

这是我的密码:

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" type="application/javascript"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!---
<cfquery name="data" datasource="#application.dsn#">
    select * from yourTable 
</cfquery>

--->

<!--- Generate fake data --->
<cfset data = queryNew("id,name","integer,varchar")>
<cfloop index="x" from="1" to="80">
    <cfset queryAddRow(data, {id:x,name:"User #x#"})>
</cfloop>

    <cfparam name="URL.PageId" default="0">
<cfset RecordsPerPage = 5>




<cfset TotalPages = (data.Recordcount/RecordsPerPage)-1>
<cfset StartRow = (URL.PageId*RecordsPerPage)+1>
<cfset EndRow = StartRow+RecordsPerPage-1>
<cfoutput>
 <table border="1">
   <tr>
      <th>No.</th>
      <th>PARKNAME</th>
      <th>REGION </th>
      <th>STATE</th>
   </tr>
   <cfloop query="data">
    <cfif CurrentRow gte StartRow >
       <tr>
          <td>#CurrentRow#</td>
          <td>#name#</td>
          <td>US</td>
          <td>MO</td>
       </tr>
    </cfif>
    <cfif CurrentRow eq EndRow>
       <cfbreak>
    </cfif>
   </cfloop>
</cfoutput>
   <tr>
      <td colspan="4">
       <cfloop index="Pages" from="0" to="#TotalPages#">
        <cfoutput>
           <cfset DisplayPgNo = Pages+1>
           <cfif URL.PageId eq pages>
              <strong>#DisplayPgNo#</strong>
           <cfelse>
              <a href="?PageId=#Pages#">#DisplayPgNo#</a>
           </cfif>
        </cfoutput>
       </cfloop>
      </td>
   </tr>
</table>




 <nav aria-label="...">
  <ul class="pagination">
    <li class="page-item disabled">
      <a class="page-link" href="#" tabindex="-1">Previous</a>
    </li>
      <cfloop index="Pages" from="0" to="#TotalPages#">
        <cfoutput>
           <cfset DisplayPgNo = Pages+1>
           <cfif URL.PageId eq pages>
                <li class="page-item">
                    <li class="page-item active">
                    <a class="page-link" href="##">#DisplayPgNo#</a>
               </li>
           <cfelse>
               <li class="page-item"><a class="page-link" href="?PageId=#Pages#">#DisplayPgNo#</a></li>
           </cfif>
        </cfoutput>
       </cfloop>
        <li class="page-item">
            <a class="page-link" href="#">Next</a>
        </li>
  </ul>
</nav>

以前的应该是这样的

<li class="page-item <cfif url.pageid LTE 1>disabled</cfif>">
  <a class="page-link" href="?Pagesid=#(url.pageid - 1)#" tabindex="-1">Previous</a>
</li>

Next的类似代码这里是一个完整的分页解决方案。尽管您可能希望将paginateBS函数放在可重用的应用程序变量中

<!--- CURRENT PAGE --->
<cfparam name="url.page" default="1">
<cfparam name="request.PAGI_pagenum" default="#url.page#">
<!--- RECORDS PER PAGE (ON ALL PAGES) --->
<cfparam name="request.PAGI_allperpage" default="20">
<!--- RECORDS PER PAGE (ON FIRST PAGE) --->
<cfparam name="request.PAGI_firstperpage" default="#request.PAGI_allperpage#">
<!--- NUMBER OF PAGE LINKS AT A TIME --->
<cfparam name="request.PAGI_blocksof" default="5">

<cfset fromRecord = request.PAGI_firstperpage+(request.PAGI_allperpage*(request.PAGI_pagenum-1))-request.PAGI_allperpage>
<cfquery name="quotes" >
SELECT SQL_CALC_FOUND_ROWS first_name, last_name, email, id, datetime, published
FROM quotes
ORDER by datetime DESC
LIMIT #fromRecord#,
    <cfif request.PAGI_pagenum is 1>
        #request.PAGI_firstperpage#
    <cfelse>
        #request.PAGI_allperpage#
    </cfif>
</cfquery>
<Cfquery name="result_count" >
SELECT FOUND_ROWS() as totalRecords
</cfquery>


<div class="pull-right" id="page">
    <div class="pagination pagination-custom">
        <ul>
            <cfoutput>#paginateQuotes(totalRecords=result_count.totalRecords)#</cfoutput>
        </ul>
    </div>
</div>


<cffunction name="paginateBS">
    <cfargument name="totalRecords" default="0">
    <cfparam name="request.PAGI_attribute" default="">
    <!--- 'TOP' IS THE LAST PAGE NUMBER LINK --->
    <Cfset top = request.PAGI_blocksof * ceiling((request.PAGI_pagenum)/request.PAGI_blocksof)>

    <cfoutput>

    <!--- IF WE'RE PAST THE FIRST BLOCK OF PAGES, SHOW THE PREV LINK --->
    <cfif request.PAGI_pagenum gt request.PAGI_blocksof>
        <li>
            <a href="?page=#top-request.PAGI_blocksof#<cfif request.PAGI_attribute neq ''>&#request.PAGI_attribute#=#request.PAGI_attributevalue#</cfif>">
                <i class="icon-double-angle-left"></i>
            </a>
        </li>
    </cfif>

    <!--- LOOP THROUGH THE PAGES IN THIS BLOCK --->
    <cfloop from="#top-request.PAGI_blocksof+1#" to="#top#" index="a">
        <li <cfif request.PAGI_pagenum is not a>class="active"</cfif>>
            <a href="?page=#a#<cfif request.PAGI_attribute neq ''>&#request.PAGI_attribute#=#request.PAGI_attributevalue#</cfif>">#a#</a>
        </li>
        <!--- IF WE'RE ON THE LAST BLOCK AND DON'T HAVE ENOUGH RECORDS TO COMPLETE THE BLOCK,
            STOP CREATING THE LINKS FOR MORE PAGES, AND SET A FLAG TO NOT SHOW THE LINK FOR THE NEXT BLOCK --->
        <cfif ((a-1) * request.PAGI_allperpage) + request.PAGI_firstperpage gte arguments.totalRecords>
            <cfset arguments.noNext=1>
            <cfbreak>
        </cfif>
    </cfloop>

    <!--- IF WE RAN OUT OF RECORDS, DO NOT SHOW THE LINK FOR THE NEXT BLOCK OF PAGES --->
    <cfif not isdefined("arguments.noNext")>
        <li>
            <a href="?page=#top+1#<cfif request.PAGI_attribute neq ''>&#request.PAGI_attribute#=#request.PAGI_attributevalue#</cfif>">
                <i class="icon-double-angle-right"></i>
            </a>
        </li>
    </cfif>

    </cfoutput>
</cffunction>
我最终使用了 分页,在此发布,希望它能帮助像我这样的其他人:


谢谢你们帮助我

您的“数据”查询正在将每条记录拉回来,而不考虑页面。你应该把查询限制在你需要的记录上。是的,你的权利,这就是我正在做的,只是我缺少了一个部分如何控制上一个/下一个,例如{prev 1 2 3 4 5 6 next}下一步单击{prev 7 8 9 10 11 12 next}与上一步相同。。。