count currentrow of cfoutput inside cfoutput
here is the situation, i have a table that displays some values, moreover there are one cfoutput inside the other, thus the currentrows are counted separately, anyway, i hope everything will be clear after source:
<cfquery name="get_products" datasource="#dsn3#">
SELECT P.PRODUCT_ID,P.PRODUCT_NAME,PS.MONEY,PR.PRICE,P.BRAND_ID,PS.PRICE,GSL.PRODUCT_STOCK,GSL.PURCHASE_ORDER_STOCK,GSL.SALEABLE_STOCK,P.PRODUCT_DETAIL2,P.BARCOD
FROM PRODUCT P
JOIN PRICE_STANDART PS ON P.PRODUCT_ID = PS.PRODUCT_ID
JOIN PRICE PR ON P.PRODUCT_ID = PR.PRODUCT_ID
JOIN #DSN2_ALIAS#.GET_STOCK_LAST GSL ON P.PRODUCT_ID = GSL.PRODUCT_ID
<cfif isdefined('attributes.is_stock') and attributes.is_stock is 1>
AND GSL.PRODUCT_STOCK > 0
</cfif>
<cfif isdefined('attributes.product_catid') and len(attributes.product_catid)>
JOIN PRODUCT_CAT PC ON P.PRODUCT_CATID = PC.PRODUCT_CATID
</cfif>
WHERE PS.PURCHASESALES=1 AND PS.PRICESTANDART_STATUS=1 AND P.IS_SALES=1 AND P.IS_PURC开发者_开发知识库HASE=1 AND P.IS_INTERNET=1 AND P.IS_EXTRANET=1
AND PR.STARTDATE <= #now()# AND (PR.FINISHDATE >= #now()# OR PR.FINISHDATE IS NULL)
GROUP BY P.PRODUCT_ID,PR.PRICE,P.PRODUCT_NAME,PS.MONEY,P.BRAND_ID,PS.PRICE,GSL.PRODUCT_STOCK,GSL.PURCHASE_ORDER_STOCK,GSL.SALEABLE_STOCK,P.PRODUCT_DETAIL2,P.BARCOD
P.PRODUCT_ID, PR.PRICE DESC
</cfquery>
then table:
<cfoutput query="get_products" startrow="#attributes.startrow#" maxrows="#attributes.maxrows#" group="product_id">
<tr height="20" onMouseOver="this.className='color-light';" onMouseOut="this.className='color-row';" class="color-row">
<td>
<a href="/index.cfm?fuseaction=product.form_upd_product&pid=#product_id#" style="color:blue;" target="_blank">#left(product_name,50)#</a>
</td>
<td>#left(PRODUCT_DETAIL2,50)#</td>
<td align="center"><cfif len(brand_list)>#get_brands.brand_name[listfind(brand_list,brand_id,',')]#</cfif></td>
<td align="center">#PRODUCT_STOCK#</td>
<td align="center">#saleable_stock#</td>
<td align="center">#purchase_order_stock#</td>
<cfoutput><td align="center">#tlformat(price,2)# <cfif currentrow eq 4>asd</cfif></td></cfoutput>
<td align="center"><a href="javascript://" onclick="gizle_goster(abr#currentrow#);" style="font-weight:bold;">x #saleable_stock#</a></td>
<td align="center">#MONEY#</td>
</tr>
<tr onMouseOver="this.className='color-light';" onMouseOut="this.className='color-row';" class="color-row" id="abr#currentrow#" style="display:none;">
<td colspan="3"></td>
<td colspan="3" style="color:blue;font-weight:bold;text-align:center;">#saleable_stock# x</td>
<cfoutput>
<td align="center" style="color:red;font-weight:bold;text-align:center;">#tlformat((saleable_stock*price),2)#</td>
<cfset abr = tlformat((saleable_stock*price),2)>
</cfoutput>
<td align="center" colspan="2">#MONEY#</td>
</tr>
</cfoutput>
and the result: http://s008.radikal.ru/i303/1110/2a/031496096958.png
as you can see writing "asd" is only displayed in the first row of the outside cfoutput, but in the 4th row of the inside cfoutput. ( there are 4 prices in one row ) All i want is to write the "asd" in every row of the outside cfoutput, and in the 4th row of the inside row.
Thank you all for the help!
When you do a grouped output, the CURRENTROW var of a CFQUERY doesn't behave like you would think.
The quickest solution would be to set and increment a new variable within your grouped output, here:
<cfset iter = 1 />
<cfoutput><td align="center">#tlformat(price,2)# <cfif iter eq 4>asd</cfif></td><cfset iter++ /></cfoutput>
Be sure to reset the var at the start of any new grouped output (so duplicate this code in your second <TR>
row as well).
精彩评论