tags:

views:

101

answers:

1

Hi I have a query which retrieves Some data. I want to display that data considering some conditions in different div tags. Now my question is, I am doing this by looping the query once and getting the data in three different structs and using these structs while displaying. Is this a good approach or looping through the query everytime in each div to check the condition is the rirht approach ?

     <tr >
<td >
  features:
 </td>
 <td >
    <cfloop query="getAttributes">
      <cfif getAttributes.type_id EQ 1>
        #getAttributes.seat#<br>
      </cfif>
    </cfloop>
 </td>
</tr>
<tr>
 <td >
  Disclosures:
 </td>
 <td >
    <cfloop query="getAttributes">
   <cfif getAttributes.type_id EQ 2>
          #getTicketAttributes.seat#<br>
   </cfif>
  </cfloop>
  </td>
 </tr> 

Or can i use the below approach

seatStruct 
disclosureStruct 
<cfloop query="getAttributes">  
<cfif getAttributes.type_id EQ 1> 
Insert seatStruct 
<cfelseif getAttributes.type_id EQ 2> 
insert disclosureStruct 
</cfif> 
Now use these structs to display
+3  A: 

I think you'll have to edit your question a little bit, put some example.

Less looping is always the best approach :) Less conversion if not necessary is best approach :)

If your data is in one query, than there's no need to loop more than once, I guess...

zarko.susnjar
Hi i have added the code. Instead of doing the above way can i get the content in two diff structs and use them?Like...seatStructdisclosureStruct<cfloop query="getAttributes"> <cfif getAttributes.type_id EQ 1>Insert seatStruct<cfelseif getAttributes.type_id EQ 2>insert disclosureStruct</cfif>Now use these structs to display.
Somu
You could also do query of queries:<cfquery name="getData1" dbtype="query"> SELECT <columns> FROM getAttributes WHERE type_id = 2</cfquery>and same for type_id = 1So again no need to convert to structs.
zarko.susnjar
Ok,Does that mean to say querying is the best way rather than using the structs ?
Somu
IMHO if you have data stored in query, use it as query. If it doesn't fit to your display needs, change the query. No need to convert/parse all this just for simple table output. More over, you dont have nested data or such so keep it simple.
zarko.susnjar
Yo.. Thanks Zarko. Actualy your approach is good. Thanks i didnt knew this querying the query :) (New to CF)
Somu