2011-08-15 107 views
0

我想創建一個產品列表與其每個產品,它的價格表,但問題是,我不能加入兩個查詢,因爲我想要一個輸出插入到另一個輸出,但它是不可能實現只是把他們這樣,我知道我必須加入2個SQL查詢,以使他們正常工作,再加上每個產品有4個價格,無論如何,爲了使它更清楚我做了一個截圖我的方式希望它看到:http://s44.radikal.ru/i106/1108/57/33380d0557f4.jpg這裏是查詢:cfoutput內cfoutput

產品查詢:

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

解釋意味着我插入他們,並由我自己計算,但它應該從價格列表我想要整合,但我不能... 謝謝大家的幫助!

回答

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> 

如果價格表中的每個產品收益超過一個價格,然後你可以使用組屬性。欲瞭解更多信息,請看這裏:http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7ff6.html

+0

非常感謝! )) – user775917

+0

我該如何使用這個團隊,起初我很喜歡它的工作,但它沒有,有多個產品,有一個價格,我想要一個產品有多個價格,我想我必須使用團體,但怎麼樣?! – user775917

+0

您需要通過product_code對查詢進行排序,然後將'group =「product_code」'添加到'cfquery'標籤。 *然後*,您需要添加另一個''標籤(沒有屬性)圍繞您想要重複的價格。肯定會對''標籤的組屬性進行一些閱讀,你會很開心。 –