Specifying number of rows in a CFLOOP query

Good morning everyone...I have a question/problem which I hope is simple but I'm having a hard time coming up with a solution., I have a simple query, and that query will return several rows of information about a specific project. Each row has a specific id number. I can display the query results using CFLOOP and everything works fine. But what I want to do is a) only show three records (the last three entered) instead of every records and then b) have a button or link where the user can select to show the remaining records. My query is below:

<CFQUERY DATASOURCE="MCA_Oracle" NAME="GetExcludeCurDocCommentList">
 SELECT UNOB_REMARKS.*
 FROM MCA.UNOB_REMARKS
 WHERE UNOB_REMARKS.MIPR_ID = '#SESSION.urlpass.MIPR_ID#'
 ORDER BY UNOB_REMARKS.LAST_REMARK_UPDATE DESC
 </CFQUERY>

and then all I'm doing with the CFLOOP is:

<TABLE>


<CFLOOP query="GetExcludeCurDocCommentList">
<TR>
<TD><CFINPUT TYPE="Text"
                     NAME="Exs_DATE"
                     VALUE="#DateFormat(GetExcludeCurDocCommentList.LAST_REMARK_UPDATE,'mm/dd/yyyy')#"
                     SIZE="12"
                     MAXLENGTH="25"
                     style="border-color:WHITE; border-width:2; background-color:D1D0CE" readonly="Yes"></TD>

<TD><textarea rows="2" cols="73" name="Exs_Remark" style="border-color:WHITE; border-width:2; background-color:D1D0CE" readonly>#GetExcludeCurDocCommentList.REMARKS#</textarea></TD>

<TD><CFINPUT TYPE="Text"
                     NAME="Exs_ID"
                     VALUE="#GetExcludeCurDocCommentList.ID#"
                     SIZE="5"
                     MAXLENGTH="25"
                     style="border-color:WHITE; border-width:2; background-color:D1D0CE" readonly="Yes"></TD>
</tr></CFLOOP></TABLE>

Any help would be greatly appreciated!!!
diecasthft01Asked:
Who is Participating?
 
gdemariaCommented:
You could set a "TOP X" on your select to show just the three records.

Then the button will redraw the screen with a new number for the maxRows value

<cfparam name="url.maxRows" default="3">

<CFQUERY DATASOURCE="MCA_Oracle" NAME="GetExcludeCurDocCommentList">
 SELECT top #maxRows# UNOB_REMARKS.*
 FROM MCA.UNOB_REMARKS
 WHERE UNOB_REMARKS.MIPR_ID = '#SESSION.urlpass.MIPR_ID#'
 ORDER BY UNOB_REMARKS.LAST_REMARK_UPDATE DESC
</CFQUERY>


<a href="xxxx?maxRows=9999">Show All</a>

Open in new window

0
 
diecasthft01Author Commented:
That's perfect. That works exactly as I want it to. Thanks a lot!!!
0
 
_agx_Commented:
Don't forget to wrap it in a val() to protect against sql injection , ie val(url.maxRows)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.