2014-10-04 27 views
0

我在從ColdFusion表單獲取信息到操作頁面並顯示所需內容方面遇到了一些麻煩。基於從表單中選擇的產品,我必須顯示此產品的選定產品和公司名稱。ColdFusion SELECT通過表單中的INNER JOIN

這裏是我的表單頁面的代碼:

<form action="productinfo.cfm" method="post"> 
    <cfoutput query = "getProducts"> 
    ... 
    <input type="radio" name="prods" value="#getProducts.productname#"> 
    #getProducts.productname# 
    ... 
    </cfoutput> 
    <input type="submit" value="Submit"> 
</form> 

這裏是我的行動網頁代碼:

<cfset prodname = form.prods> 

<cfquery name = "JoinProdSupp" datasource = "jeb48_northwind"> 
    SELECT Products.ProductName, Suppliers.CompanyName 
    FROM Suppliers INNER JOIN Products 
       ON Suppliers.SupplierID = Products.SupplierID 
    WHERE (((Products.ProductName)='#prodname#')); 
    </cfquery> 

我不完全知道如何輸出查詢的內容。

回答

1

我敢肯定,我想通了這一點......如果任何人有任何意見,我所有的耳朵。這是我結束了。

 <cfoutput query = "JoinProdSupp"> 
     #JoinProdSupp.ProductName#<br> 
     #JoinProdSupp.CompanyName#<br> 
    </cfoutput> 
+1

當您運行查詢時,出於各種原因,您應該使用查詢參數。在你的輸出代碼中,由於你的cfoutput標籤中有一個查詢屬性,因此不需要使用查詢名稱來限定變量。 – 2014-10-04 09:19:10

+2

@DanBracuk是正確的,並要清楚,他的意思這樣.. WHERE(((Products.ProductName)= ))。 CFQueryParam是針對sql注入的關鍵防禦。 http://help.adobe.com/livedocs/coldfusion/8/htmldocs/help.html?content=Tags_p-q_18.html。還要注意標記周圍缺少引號,cfqueryparam根據所選的cfsqltype指定添加引號。 – 2014-10-04 16:09:03

+2

查詢名稱確實是不必要的,但如果該cfoutput塊增長並且變得更加複雜,那麼將它放在那裏真的很不錯,尤其是當其他人出現並試圖找出變量來自何處時。 – Barry 2014-10-08 16:26:04

1

作爲參考..

你想了解任何CF變量的內容的任何時間,(數組,結構,查詢,任何那些嵌套在任何那些的,嵌套在任何這些的)你可以使用CFDUMP。

<cfdump var="#MyQuery#"> 

(注意周圍的變量名的哈希值,這些都是很重要的。)

關注,如果你執行這個腳本會發生什麼。 (此腳本使用語法從CF 8或以上)

<cfscript> 
    s_struct = {}; // Create an empty structure. 
    s_struct.sample_array = ["sample","array","data"]; // Create an array with three elements 
    s_struct.sample_array[4] = {one = 1,banana = "yellow"}; // Add a fourth element to the same array, whose content is a struct with two elements. 
    s_struct.second_array = [{cat = "dog", red = "blue", big = "small"},{cat = "feline", dog = "canine", big = "large"}]; 
    s_struct.FirstArraySize = ArrayLen(s_struct.sample_array); 
</cfscript> 

<cfdump var="#s_struct#"> 

一個cfdump的輸出基本上教你如何訪問一個變量,它可與記錄不完整的網絡服務,或表有幫助的內容,即你不能直接訪問。只記得總是清理生產中的cfdumps。