0

I need help looping through my data and outputting it into multiple columns. Currently, it displays vertically right under the next set of data in the array. Please help.

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

1 Answer 1

2

You want the City, State and Zip Code to be headers? Then this would work

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

It works because <tr></tr> defines a table row and <td></td> defines a cell in that row. In your case, you were doing multiple rows without cells, thus you were getting your content in a column, instead of a row. A side note is that <cfoutput></cfoutput> should be used only once per page and not around every variable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.