Solved

(gdemaria) I need to do pagination to my list

Posted on 2014-03-12
9
200 Views
Last Modified: 2014-03-13
Hi,

I have a list of parent Issues and child Issues that I need to be able to display just 10 records on a time and do the pagination


<cfquery name = "QSearchResult"  datasource='#strDSN#' username='#strUID#' password='#strPWD#'>
  SELECT case when ParentIssueID is null then IssueId
              else ParentIssueID
		 end  as TopIssueID
		 , IssueID
		 , ParentIssueID
		 , TicketNumberTxt
		 , TitleOfIssue
		 , Status
		 , DateCreated
   FROM LogEntry
  order by 1 desc, case when parentIssueID is null then 1 else 2 end
</cfquery>



<cfparam name="url.page" default="1">
<cfset page_links_shown = 5>
<cfset records_per_page = 10>

<cfset start_record = url.page * records_per_page - records_per_page>
<cfset total_pages = ceiling(QSearchResult.count/ records_per_page)>


<table>
<cfoutput query="QSearchResult">
<tr>
 <cfif val(QSearchResult.ParentIssueID)> 
   <td style="padding-left:20px;">
 <cfelse>
   <td> 
 </cfif>
   #QSearchResult.issueID#
 </td>
 <td>#QSearchResult.ticketNumberTxt#</td>
 <td>#QSearchResult.TitleOfIssue#</td>
 <td>#QSearchResult.Status#</td>
</tr>
</cfoutput>
</table>
  


<cfif url.page EQ 1>
   Prev Page
<cfelse>
   <a href="index.cfm?page=#url.page-1#">Prev Page</a>
</cfif>
<hr>


<cfif url.page * records_per_page LT QSearchResult.counts>
   <a href="pages.cfm?page=#url.page+1#">Next Page</a>
<cfelse>
   Next Page
</cfif>
<hr>

Open in new window

0
Comment
Question by:lulu50
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 39

Expert Comment

by:gdemaria
ID: 39924393
A couple questions -

when counting the 10 records to show on a page.   Is that ten comprised of parent and child issues together?    Or are we counting only 10 parent issues and showing any number of child issues that may happen to belong?

I assume it is the first, that the total number of records will be 10.  But when you go to page two, you have to be aware that you may be showing a child issue with no parent on the same page.    For example, if you have a parent issue with 5 child issues, the parent issue could show as record 8 on the first page, then show 1 child issue on the first page, then on the second page would show just 3 child issues with no parent.   That is ok?

How many total records might there be?   For example, there may be about 100 total records which would be 10 pages of 10 records each?   Or are we talking thousands?    If the number if fairly small, we can do it the easy way.
0
 

Author Comment

by:lulu50
ID: 39926079
gdemaria,

I want to thank you first for all your help.

it's going to have thousands of records.

no, I can't have a child without a parent on the second page.  So,
I have to display 10 parent records regardless of how many child records it has.
0
 

Author Comment

by:lulu50
ID: 39926690
gdemaria,

where are you?

Did you forget about me today? :-(
0
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
LVL 39

Expert Comment

by:gdemaria
ID: 39926778
sorry - doctor appointment :)

Check this one out - this is the straight-forward 10 records per page, I modified the start-record variable just a bit and added startRow and MaxRows to the cfoutput


<cfquery name = "QSearchResult"  datasource='#strDSN#' username='#strUID#' password='#strPWD#'>
  SELECT case when ParentIssueID is null then IssueId
              else ParentIssueID
		 end  as TopIssueID
		 , IssueID
		 , ParentIssueID
		 , TicketNumberTxt
		 , TitleOfIssue
		 , Status
		 , DateCreated
   FROM LogEntry
  order by 1 desc, case when parentIssueID is null then 1 else 2 end
</cfquery>



<cfparam name="url.page" default="1">
<cfset page_links_shown = 5>
<cfset records_per_page = 10>

<cfset total_pages = ceiling(QSearchResult.count/ records_per_page)>

<cfif val(url.page) lt 1>
  <cfset url.page = 1>
<cfelseif val(url.page) gt total_pages>
  <cfset url.page = total_pages>
</cfif>
<cfset start_record = ((url.page - 1) * records_per_page ) + 1>


<table>
<cfoutput query="QSearchResult" startrow="#start_record#" maxrows="#records_per_page#">
<tr>
 <cfif val(QSearchResult.ParentIssueID)> 
   <td style="padding-left:20px;">
 <cfelse>
   <td> 
 </cfif>
   #QSearchResult.issueID#
 </td>
 <td>#QSearchResult.ticketNumberTxt#</td>
 <td>#QSearchResult.TitleOfIssue#</td>
 <td>#QSearchResult.Status#</td>
</tr>
</cfoutput>
</table>
  


<cfif url.page EQ 1>
   Prev Page
<cfelse>
   <a href="index.cfm?page=#url.page-1#">Prev Page</a>
</cfif>
<hr>


<cfif url.page * records_per_page LT QSearchResult.counts>
   <a href="pages.cfm?page=#url.page+1#">Next Page</a>
<cfelse>
   Next Page
</cfif>
<hr>

Open in new window

0
 

Author Comment

by:lulu50
ID: 39926873
gdemaria!!!!!!

oh, I hope everything is ok!!!!

I made a lots of changes to it so I posted my most recent changes.

I set it to display just 2 records on a time for testing purpose.

I got it to work, but is it possible to have it like this instead

Prev 3 4 5 6 7 Next

it will be nice to have some numbers between them.

Thank you so much for all your help.



 <cfquery name = "QSearchResult"  datasource='#strDSN#' username='#strUID#' password='#strPWD#'>
  SELECT case when L.ParentIssueID is null then L.IssueId
              else L.ParentIssueID
		 end  as TopIssueID
		 , L.IssueID
		 , L.ParentIssueID
		 , L.TicketNumberTxt
		 , L.TitleOfIssue
		 , I.Status
		 , L.DateCreated
   FROM LogEntry L
   LEFT JOIN IssueStatus I on I.StatusID = L.StatusID
  order by 1 desc, case when L.parentIssueID is null then 1 else 2 end
</cfquery>


<cfparam name="url.page" default="1">
<cfset page_links_shown = 5>
<cfset records_per_page = 2>

<cfset total_pages = ceiling(QSearchResult.RecordCount / records_per_page)>

<cfif val(url.page) lt 1>
  <cfset url.page = 1>
<cfelseif val(url.page) gt total_pages>
  <cfset url.page = total_pages>
</cfif>
<cfset start_record = ((url.page - 1) * records_per_page ) + 1>



<table style="width:100%;border: solid 1px #dddddd;" id="ResultListTbl">

<tr style="background-color:#d0d2d3;font-weight:bold;">
 <th style="width:80px;padding-left:3px;">Issue ID</th>
 <th style="width:100px;">Ticket#</th>
 <th style="width:300px;">Title</th>
 <th style="width:50px;">Status</th>
 <th style="width:100px;">Date</th>
  <th style="width:50px;">&nbsp;</th>
</tr>

<cfoutput query="QSearchResult" startrow="#start_record#" maxrows="#records_per_page#">

 <cfif val(QSearchResult.ParentIssueID)> 
 <!-- //Child Row -->
 <tr>
   <td style="padding-left:20px;">#QSearchResult.issueID#</td>
 <td>#QSearchResult.ticketNumberTxt#</td>
 <td>#QSearchResult.TitleOfIssue#</td>
 <td>#QSearchResult.Status#</td>
  <td>#DateFormat(QSearchResult.DateCreated, "m/d/yyyy")#</td>
    <td>Edit</td>
    </tr>
 <cfelse>
<!-- //Parent Row -->
 <tr class="bgrow">
   <td style="font-weight:bold;">#QSearchResult.issueID#</td>
 <td>#QSearchResult.ticketNumberTxt#</td>
 <td>#QSearchResult.TitleOfIssue#</td>
 <td>#QSearchResult.Status#</td>
  <td>#DateFormat(QSearchResult.DateCreated, "m/d/yyyy")#</td>
  <td>Edit</td>
  </tr>
 </cfif>
   

</cfoutput>
</table> 
   
   <cfoutput>
  <cfif url.page EQ 1>
   Prev Page
<cfelse>
   <a href="index.cfm?page=#url.page-1#">Prev Page</a>
</cfif>
<hr>


<cfif url.page * records_per_page LT QSearchResult.RecordCount >
   <a href="index.cfm?page=#url.page+1#">Next Page</a>
<cfelse>
   Next Page
</cfif>
<hr>
  
  </cfoutput>

Open in new window

0
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 39926912
how about something like this?

<cfoutput>
<hr>
<cfif url.page EQ 1>
   &laquo; Prev
<cfelse>
   <a href="index.cfm?page=#url.page-1#">&laquo; Prev</a>
</cfif>
&nbsp;|&nbsp;
<cfloop index="pp" from="1" to="#total_pages#">
  <cfif pp eq url.page>
   <strong>#pp#</strong> <!--- current page ---->
  <cfelse>
   <a href="index.cfm?page=#pp#">#pp#</a>
  </cfif>&nbsp;|&nbsp;
</cfloop>
<cfif url.page lt total_pages>
   <a href="index.cfm?page=#url.page+1#">Next &raquo;</a>
<cfelse>
   Next &raquo;
</cfif>
<hr>
</cfoutput>

Open in new window

0
 

Author Comment

by:lulu50
ID: 39927001
gdemaria,

That is awesome!!!!!!!!!!!!!!!!!

I am very happy with it!!!!!!!!!!!!!!!!!!!1

It looks great!!!!!!!!!11

Can't thank you enough

Thank you for one million and one times lol

Thanks again and again

Lulu
0
 

Author Closing Comment

by:lulu50
ID: 39927003
Excellent+++
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 39927531
:)   you are very welcome
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
https json cfhttp post 1 211
Having an issue with NumberFormat 7 66
query of query sort 6 116
Combining Queries 7 54
The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question