数据库 – 循环或输出中的最后和第一个内容(coldfusion)

我想知道是否有可能显示从ColdFusion中的Loop或Output中获取的特定内容,例如我有一个输出
<cfoutput query="get_service_plus"><b>#SUBJECT#</b><br/>#plus_content#<br/></cfoutput>

及其查询,以防万一:

<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>

我知道我最有可能应该使用循环从db获取特定内容但无法理解如何实现它… thx求救!

解决方法

你可以做几件事.

如果循环完整查询,可以使用变量“qet_service_plus.currentrow”检查当前行号,

<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>

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 &#39;EastRiver&#39; 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...