Last and first content in a loop or output (coldfusion)

I wonder if it is possible to display specific content taken from Loop or Output in ColdFusion, for example, I have the output:

<cfoutput query="get_service_plus"><b>#SUBJECT#</b><br/>#plus_content#<br/></cfoutput>

and his request, just in case:

<cfquery name="GET_SERVICE_PLUS" datasource="#DSN3#">
    SELECT 
        *
    FROM 
        SERVICE_PLUS
    WHERE   
        SERVICE_ID = #attributes.action_id#
      <cfif isDefined("GET_SERVICE_PLUS.SERVICE_PLUS_ID")>
        AND SERVICE_PLUS_ID = #GET_SERVICE_PLUS.SERVICE_PLUS_ID#
      </cfif>
      ORDER BY PLUS_DATE DESC,RECORD_DATE DESC
</cfquery>

I know that I most likely should use loops to get specific content from db, but could not figure out how to achieve it ... thanks for reference!

+7
source share
2 answers

There are a few things you can do.

If you complete the full query, you can check your current line number with the variable "qet_service_plus.currentrow", therefore

<cfif qet_service_plus.currentrow eq 1>
   <!--- do first row display stuff --->
</cfif>

, . "recordcount",

<cfif get_service_plus.currentrow eq get_service_plus.recordcount>
   <!--- do last row display stuff --->
</cfif>

, , cfquery . .

<cfoutput>
<!--- service id in first record --->
#get_service_plus['service_id'][1]# 
<!--- service id in last record --->
#get_service_plus['service_id'][get_service_plus.recordcount]# 
</cfoutput>
+14

, CF:

<cfoutput query="get_service_plus">

  <cfif get_service_plus.currentRow eq 1 or get_service_plus.currentRow eq get_service_plus.recordCount>
    <b>#SUBJECT#</b><br/>#plus_content#<br/>
  </cfif>

</cfoutput>

, , .

, , , .

, .

0

All Articles