Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

last and first content in loop or output (coldfusion)

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

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

and its query, 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 probably should use the loops to get the specific content from db but couldn't understand how to achieve it... thx for help!

like image 656
abrabr Avatar asked Feb 21 '11 10:02

abrabr


1 Answers

There are a couple of things you can do.

If you are looping the complete query you can check your current row number by using the variable "qet_service_plus.currentrow", so

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

With every query also comes the number of records returned in the query. You can find this in "recordcount", so

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

If you want to get to a specific record in a query without going through the complete query you can treat a cfquery as an associative array. eg.

<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>
like image 58
Stephen Moretti Avatar answered Oct 19 '22 12:10

Stephen Moretti