来自Form的INNER JOIN的ColdFusion SELECT

时间:2014-10-04 04:03:16

标签: forms coldfusion

我在从ColdFusion表单获取信息到操作页面并显示所需内容时遇到了一些麻烦。我必须根据从表单中选择的产品显示此产品的所选产品和CompanyName。

以下是我的表单页面中的代码:

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

我不确定如何输出查询内容。

2 个答案:

答案 0 :(得分:1)

我很确定我已经明白这一点......如果有人有任何评论,我会全力以赴。这就是我最终的结果。

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

答案 1 :(得分: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的输出基本上教你如何访问变量的内容,这对于记录不良的web服务或者你无法直接访问的表有用。请记住始终从生产中清理cfdumps。