2017-06-07 10 views
2

私は以下のようなシナリオをページ上に持っています。私は、列、セクション、状態、データを持つcfc all_dataから返されるクエリを持っています。今、ページデザインは以下のようになります。クエリーのcfloopとクエリ

セクション1 section2のSECTION3 section4 - >それに

を状態を選択するための一つのセクションを選択するセクション1が選択されているとしましょう - >そのセクションに関連付けられている状態1 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のために。これは正しいアプローチです。どんな洞察にも感謝します。

+0

以下のように使用すると、グループ属性を使用することができると思います。 –

+0

どうすればよいですか? – user747291

+0

あなたのGoogle検索文字列は 'cfoutput query group'です。 –

答えて

1

私は私の心にジャンプする最初の事はCFOUTPUTのグループ属性である

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

5月も同様に 'temp'を取り除きます。使用されていない場合は結果をキャプチャしません。また、CF10 +では、手動クエリーの作成と移入のための簡単な方法が導入されました。 [QueryNew(columnlist [、columntypelist [、rowData]])]](https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-m-r/querynew.html)を参照してください。 – Leigh

1

これはどういう意味ですか?

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

入力していただきありがとうございます – user747291

関連する問題