2

我在页面上有如下场景。我有一个从 cfc all_data 返回的查询,其中包含列、部分、状态、数据。现在页面设计如下所示。

section1 section2 section3 section4 -> 选择一个部分以选择其中的状态

假设 section1 被选中 -> State1 state2 state3 与该部分关联需要显示 -> 选择一个状态以查看与其相关的数据。

说选择了 State3 -> 显示了相关的 State3 数据。

所以基本上我需要 3 个 cfloops 来完成上述工作。我在做`

<cfquery name="section" dbtype="query">
 select distinct section from all_data 
</cfquery>`

对于第一个循环,我遍历“部分”查询以显示所有部分。

<cfloop query ="section">
    <cfquery name="state" dbtype="query">
    select distinct state from all_data where section = section.section
    </cfquery>
</cfloop>

对于状态显示,我像上面一样循环。对于循环 3,即数据显示,我尝试了多种方法,但似乎没有一种方法能以正确的方式工作。这是正确的方法吗。任何见解都值得赞赏。

4

2 回答 2

1

do you mean something like this?

    <cfloop query ="section">
        <cfquery name="state" dbtype="query">
          select distinct state from all_data where section = section.section;
        </cfquery>
        <cfloop query ="state">
            <cfquery name="getdata" dbtype="query">
              select * from all_data where section = section.section 
              and state = state.state;
            </cfquery>
            <cfdump var=#getdata#>
        </cfloop>
    </cfloop>
于 2017-06-07T15:54:51.150 回答
1

我认为您可以使用 group 属性,如下所示

<cfset myQuery = QueryNew("Section, State, Data", "VarChar, VarChar, VarChar")> 

<cfset newRow = QueryAddRow(MyQuery, 5)> 

<!--- Set the values of the cells in the query ---> 
<cfset temp = QuerySetCell(myQuery, "Section", "Section 1", 1)> 
<cfset temp = QuerySetCell(myQuery, "State", "State 1", 1)> 
<cfset temp = QuerySetCell(myQuery, "Data", "Data 1", 1)> 
<cfset temp = QuerySetCell(myQuery, "Section", "Section 1", 2)> 
<cfset temp = QuerySetCell(myQuery, "State", "State 2", 2)> 
<cfset temp = QuerySetCell(myQuery, "Data", "Data 2", 2)> 
<cfset temp = QuerySetCell(myQuery, "Section", "Section 1", 3)> 
<cfset temp = QuerySetCell(myQuery, "State", "State 2", 3)> 
<cfset temp = QuerySetCell(myQuery, "Data", "Data 3", 3)> 
<cfset temp = QuerySetCell(myQuery, "Section", "Section 2", 4)> 
<cfset temp = QuerySetCell(myQuery, "State", "State 2", 4)> 
<cfset temp = QuerySetCell(myQuery, "Data", "Data 2", 4)> 
<cfset temp = QuerySetCell(myQuery, "Section", "Section 2", 5)> 
<cfset temp = QuerySetCell(myQuery, "State", "State 2", 5)> 
<cfset temp = QuerySetCell(myQuery, "Data", "Data 3", 5)> 

 <cfoutput query ="myQuery" group="Section">
    </br>#Section# <!--- You will get distinct Sections here --->
    <cfoutput group="Section">
            </br>#State#,
            <cfoutput>#Data#,</cfoutput>
    </cfoutput>
 </cfoutput>
于 2017-06-07T17:21:06.003 回答