2012-10-18 25 views
0

我需要幫助循環瀏覽我的數據並將其輸出到多列。目前,它在數組中的下一組數據下垂直顯示。請幫忙。如何遍歷數組並輸出多列?

 <cfloop array="#UserAddresses#" index="UA"> 

       <tr> 
        <td>City: </td> 
        <td><cfif NOT Len(#UA.city.xmlText#)>N/A<cfelse><cfoutput>#UA.city.xmlText#</cfoutput></cfif></td> 
       </tr> 
       <tr> 
        <td>State: </td> 
        <td><cfif NOT Len(#UA.state.xmlText#)>N/A<cfelse><cfoutput>#UA.state.xmlText#</cfoutput></cfif></td> 
       </tr> 
       <tr> 
        <td>Zip Code: </td> 
        <td><cfif NOT Len(#UA.zipcode.xmlText#)>N/A<cfelse><cfoutput>#UA.zipcode.xmlText#</cfoutput></cfif></td> 
       </tr>        
      </cfloop> 
    </cfif> 

回答

2

你想要城市,州和郵編是頭?然後,這會工作

<cfoutput> 
    <tr> 
     <td>City: </td> 
     <td>State: </td> 
     <td>Zip Code: </td> 
    </tr> 
    <cfloop array="#UserAddresses#" index="UA"> 
     <tr> 
      <td><cfif NOT Len(UA.city.xmlText)>N/A<cfelse>#UA.city.xmlText#</cfif></td> 
      <td><cfif NOT Len(UA.state.xmlText)>N/A<cfelse>#UA.state.xmlText#<</cfif></td> 
      <td><cfif NOT Len(UA.zipcode.xmlText)>N/A<cfelse>#UA.zipcode.xmlText#</cfif></td> 
     </tr>        
    </cfloop> 
</cfoutput> 

它的工作原理,因爲<tr></tr>定義表格的行和<td></td>定義行的單元格。在你的情況下,你做了多行而沒有單元格,因此你是在一列而不是一行中獲取你的內容。值得注意的是,<cfoutput></cfoutput>應該只用於每頁一次,而不是每個變量。