Professional Web Applications Themes

Generating table rows and columns in output? - Macromedia ColdFusion

When I output the query results, I would like to display them in a 4 column table. While I can have it add a column as cell as in <td>#outputitems#</td>, how can you have it add the </tr><tr> between every four cases?...

  1. #1

    Default Generating table rows and columns in output?

    When I output the query results, I would like to display them in a 4 column
    table. While I can have it add a column as cell as in
    <td>#outputitems#</td>, how can you have it add the </tr><tr> between every
    four cases?


    Sir Fauntleroy Guest

  2. #2

    Default Re: Generating table rows and columns in output?

    The mod (modulus) function is your friend here.
    X mod Y returns the remainder from X when you've removed as many Y's as
    you can.
    e.g. 3 mod 3 = 0, 5 mod 3 = 2, 6 mod 3 = 0, 22 mod 3 = 1 etc.

    In this code, it starts a new row just before it's on cell number
    (4n)+1, i.e. 1, 5, 9 etc.
    It adds a </tr> after cells number 4, 8, etc..

    <cfset row_every = 4>
    <table border="1" cellpadding="3" cellspacing="1">
    <tbody>
    <cfloop from="1" to="20" index="cell_count">
    <cfif cell_count MOD row_every EQ 1><tr></cfif>
    <td><cfoutput>I am cell #cell_count#</cfoutput></td>
    <cfif cell_count MOD row_every EQ row_every></tr></cfif>
    </cfloop>
    </tbody>
    </table>

    Scratch Guest

  3. #3

    Default Re: Generating table rows and columns in output?


    "Scratch" <benscratchmedia.co.uk> wrote in message
    news:1114175665.936722.69360g14g2000cwa.googlegro ups.com...
    > The mod (modulus) function is your friend here.
    > X mod Y returns the remainder from X when you've removed as many Y's as
    > you can.
    > e.g. 3 mod 3 = 0, 5 mod 3 = 2, 6 mod 3 = 0, 22 mod 3 = 1 etc.
    >
    > In this code, it starts a new row just before it's on cell number
    > (4n)+1, i.e. 1, 5, 9 etc.
    > It adds a </tr> after cells number 4, 8, etc..
    >
    > <cfset row_every = 4>
    > <table border="1" cellpadding="3" cellspacing="1">
    > <tbody>
    > <cfloop from="1" to="20" index="cell_count">
    > <cfif cell_count MOD row_every EQ 1><tr></cfif>
    > <td><cfoutput>I am cell #cell_count#</cfoutput></td>
    > <cfif cell_count MOD row_every EQ row_every></tr></cfif>
    > </cfloop>
    > </tbody>
    > </table>
    >
    thanks, but these method returns the same row of data on all four cells in
    each <tr>. So i get a row of 4 product1, a row of 4 product2, etc etc


    Sir Fauntleroy Guest

Similar Threads

  1. Repeated Region across table columns NOT rows
    By Buju1210 in forum Dreamweaver AppDev
    Replies: 2
    Last Post: February 24th, 10:52 PM
  2. Generating unique values for TEXT columns
    By Frank D. Engel, Jr. in forum PostgreSQL / PGSQL
    Replies: 6
    Last Post: January 3rd, 06:39 PM
  3. Can't get value from datagrid when generating columns on the server side
    By Alex Shirley in forum ASP.NET Data Grid Control
    Replies: 2
    Last Post: September 15th, 09:24 AM
  4. Replies: 0
    Last Post: September 10th, 05:33 PM
  5. Replies: 0
    Last Post: September 10th, 05:29 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139