cfoutput里面的cfoutput

时间:2011-08-15 11:11:02

标签: sql join coldfusion

我想创建一个带有产品列表的表,其中包含每个产品及其价格表,但问题是我无法加入两个查询,因为我希望将一个输出插入到另一个输出中,但是无法实现只是把它们放在这个方式,我知道我必须加入2个SQL查询才能使它们正常工作,而且每个产品都有4个价格,无论如何,为了让它更清晰,我按照我想要的方式制作了截图请参阅:http://s44.radikal.ru/i106/1108/57/33380d0557f4.jpg,这是查询:

产品查询:

<cfquery name="get_products" datasource="#dsn3#">   SELECT DISTINCT P.*,PS.MONEY,PS.PRICE   FROM PRODUCT P,PRICE_STANDART PS    WHERE       P.IS_SALES=1        AND P.IS_PURCHASE=1         AND P.IS_INTERNET=1         AND P.PRODUCT_ID=PS.PRODUCT_ID      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>     ORDER BY PS.PRICE DESC </cfquery>

价格查询:

<cfquery name="get_prices" datasource="#dsn3#">
        SELECT PRICE, PRODUCT_ID FROM PRICE WHERE PRODUCT_ID = #PRODUCT_ID#
    </cfquery>

和表格:

<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#">
        <tr height="20" onMouseOver="this.className='color-light';" onMouseOut="this.className='color-row';" class="color-row">
            <td>#currentrow#</td>
            <td>#product_name#</td>
            <td>#tlformat(price,2)#</td>
            <td>#tlformat((price*0.5),2)#</td> <!---this is fixed price! --->
            <td>#tlformat((price*0.49),2)#</td> <!---this is fixed price! --->
            <td>#tlformat((price*0.475),2)#</td> <!---this is fixed price! --->
            <td>#tlformat((price*0.45),2)#</td> <!---this is fixed price! --->
            <td align="center">#MONEY#</td>
        </tr>
    </cfoutput>
</table>

解释“这是固定价格!”意思是我插入它们并由我自己计算,但它应该从我想要整合的价格列表中更改,但我不能...... 谢谢大家的帮助!

1 个答案:

答案 0 :(得分:4)

你真的应该加入查询:

<cfquery name="get_products" datasource="#dsn3#">   
SELECT DISTINCT P.*,PS.MONEY,PS.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>     
ORDER BY PS.PRICE DESC 
</cfquery>

如果PRICE表为每个产品返回多个价格,则可以使用的是GROUP属性。有关详细信息,请查看此处:http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7ff6.html