cfoutput group prices

[亡魂溺海] 提交于 2020-01-07 08:32:28

问题


i want to group prices according to products id, like here: http://s44.radikal.ru/i106/1108/57/33380d0557f4.jpg but i can't group them properly, there are must be one product and few prices, rather than same products and different prices for each. so far with the help of Scott Stroz, i have wrote the code:

the query:

<cfquery name="get_products" datasource="#dsn3#">
    SELECT DISTINCT P.PRODUCT_ID,P.PRODUCT_NAME,PS.MONEY,PR.PRICE
    FROM PRODUCT P
        JOIN PRICE_STANDART PS ON P.PRODUCT_ID = PS.PRODUCT_ID
        JOIN PRICE PR ON P.PRODUCT_ID = PR.PRODUCT_ID
    WHERE P.IS_SALES=1 AND P.IS_PURCHASE=1 AND P.IS_INTERNET=1 AND PS.PURCHASESALES=1 AND PS.PRICESTANDART_STATUS=1 
    <cfif len(trim(attributes.product_cat)) and len(attributes.product_code)>AND P.PRODUCT_CODE LIKE '#attributes.product_code#%'</cfif>         
    <cfif isdefined('attributes.product_id') and len(attributes.product_id)>AND P.PRODUCT_ID=#attributes.product_id#</cfif>
    GROUP BY P.PRODUCT_ID,PR.PRICE,P.PRODUCT_NAME,PS.MONEY
    ORDER BY PR.PRICE DESC
</cfquery>

and the table:

<table cellpadding="3" cellspacing="1" class="color-border" width="100%">
    <tr class="color-header">
        <td width="30" class="header_bold">No</td>
        <td><b>Ürün</b></td>
        <td class="header_bold" width="80">Liste fiyatı</td>
        <td class="header_bold" width="80">Bayı 1</td>
        <td class="header_bold" width="80">Bayı 2</td>
        <td class="header_bold" width="80">Bayı 3</td>
        <td class="header_bold" width="80">Bayı 4</td>
        <td class="header_bold" width="25">Para</td>
    </tr>
    <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>#currentrow#</td>   
            <td>#product_name#</td>
            <cfoutput group="price"><td>#tlformat(price,2)#</td></cfoutput>
            <td align="center">#MONEY#</td>
        </tr>
    </cfoutput>
</table>

thank you all guys for help!


回答1:


Assuming you have a query that looks like this:

product_id, product_name, price
1, 'test', 100
1, 'test', 200
1, 'test', 300
2, 'test2', 100
2, 'test2', 200
2, 'test2', 300

The following code would group by product id and output each individual price

<cfoutput query="get_products" group="product_id">
    #product_name#
    Prices:
    <cfoutput>
        #price#<br>
    </cfoutput>
</cfoutput>

Now, the group by in sql has nothing to do with coldfusions group in cfoutput. It's a convinience method to loop out unique rows. So when coldfusion sees two identical "product_id" it will run the nested cfoutput loop.

You can do this for as many levels you want, but in your case there only seems to be two.



来源:https://stackoverflow.com/questions/7066002/cfoutput-group-prices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!