Reputation: 125
i want to create a table with product list with its each product, its price list, but the problem is that i cant join two queries, because i want one output to be inserted in another output, but it is impossible to achieve just putting them in this way, i know that i have to join 2 sql queries in order to make them work properly, plus for each product have 4 prices, anyway, to make it more clear i made a screenshot the way i want it to see: http://s44.radikal.ru/i106/1108/57/33380d0557f4.jpg and here is the queries:
Product query:
<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>
Price query:
<cfquery name="get_prices" datasource="#dsn3#">
SELECT PRICE, PRODUCT_ID FROM PRICE WHERE PRODUCT_ID = #PRODUCT_ID#
</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#">
<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>
the explanation "this is fixed price!" means i inserted them and counted it by my own, but it should be changed from the prices list i want to integrate, but i can't... thank you all for the help!
Upvotes: 0
Views: 456
Reputation: 7519
You really should do a join on the queries:
<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>
If the PRICE table returns more than one price for each product, you could then use the GROUP attribute of . For more info on that, take a look here: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7ff6.html
Upvotes: 4