Skip to main content
June 22, 2010
Question

Table layout query

  • June 22, 2010
  • 3 replies
  • 333 views

Hi all...

I have a query that returns headings from the database. I need them to be laid out in a table style going across the row, then when 5 headings have been put in a row, then move to the next row and repeat the process until all entries have been displayed in a table.

I have no idea what type of loop to use and how to structure it.

Any help would be greatly appreciated.

Thanks

Phil

    This topic has been closed for replies.

    3 replies

    June 23, 2010

    Hi All

    Had some other problems with the query, so converted it to an array so that I could remove any duplilcates. Couldn't use an SQL distinct as there was a comma delimited list in one of the fields and that was the field that I needed to work with and they were not the same every time.

    So, having converted the comma delimited list into an array, I then removed duplicates from this array and then used the following code to output the array in the table format that I required.

    <cfset noPerRow = 5 />
    <cfset start = 1 />
    <cfset finish = noPerRow />
    <cfoutput>
         <table>
                  <cfloop condition="start lte arrayLen(cleanArray)">
                       <tr>
                            <cfloop from="#start#" to="#finish#" index="recNum">
                                        <cfset name = " " />
                                         <cfif recNum lte arrayLen(cleanArray)>
                                           <cfset name = cleanArray[recNum] />
                                         </cfif>
                                         <td class="catList"><a href="categories3.cfm?table=#URL.table#&searchItem=#name#">#name#</a></td>
                               </cfloop>
                            <cfset start = finish+1 />
                            <cfset finish += noPerRow />
                       </tr>
                  </cfloop>
         </table>
    </cfoutput>

    Inspiring
    June 22, 2010

    <tr>

    <cfoutput query="yourquery">

    <td>#data#</td>

    <cfif currentrow mod 5 is 0></tr><tr></cfif>

    </cfoutput>

    </trr>

    June 22, 2010

    Just to give you an example of what I need...

    Sports      Menswear     Womenswear     Kids     Toys

    Lingerie    Health           Beauty              etc...

    Thanks

    Phil