Link to home
Start Free TrialLog in
Avatar of CementTruck

asked on

How to correctly create dynamic HTML table/columns/rows using cfloop

Hello Experts,

I have used CFLOOP code for several dynamically created HTML tables. I query a database table, I do a recordcount, and based on the recordcount I loop the tr and td tags to create the table. Looking at the result on a browser seems fine, but I know the code has some errors in it. I'm positive that the tr and td tags are not being closed properly, but I need to know hte correct way to do this, and an explanation of what is really transpiring. If you can post a simple example I should be able to follow your directions.

Like I said earlier, I know this code has problems, yet renders fine. I can tweak the NumofColumns, and it seems to respect the change. I don't understand MOD and what it does, and how it works in relation to the recordcount.

Any help is greatly appreciated.
<cfif UserIDCount LT 30>
   <CFSET NumOfColumns = 3>
   <CFSET NumOfColumns = 6>
     <tr >	
(the rest of the table information here it is basically a loop of one row with two columns)
Image1 here :Text1 here  :  Image 2 here :Text 2 Here  ......etc.
       <CFIF myUsers.CurrentRow MOD NumOfColumns EQ 0>

Open in new window

Avatar of James Rodgers
James Rodgers
Flag of Canada image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CementTruck



Your stuff works great, as usual! ;)

One more "little" thing; My opening loop is actually looping a query for UserIDs, and I am getting errors saying that "FROM" and "TO" attributes are not allowed when looping a query. How can I get this to work in a query situation? I'm sure it's just some little thing I'm overlooking.
<cfloop query="nameOfQuery">
thats it, the clfloop tag understnads the start and end of a query so you just give it the query name, you can give it a start row and end row, optional, can be used for paging output, but if not specified start is 1 and end is query.recordCount
in this line
<CFIF idx MOD NumOfColumns EQ 0 and idx NEQ UserIDCount>
if you are using a query switch out idx with query.currentRow, where query is the name of the query in your loop, if that doesn't work, not sure if its avaible in a looped query output, you will need to include a counter to substitute for the loop index
Ha! I guess I knew more about this subject than I thought. I had already put that code in before I got your response, and came up with another error (of sorts). The  <td>spacefiller</td> was not completing to the end of the table row. and I finally figured that out too. I was missing the <cfset iCount=0> in this bit of code :

<CFIF idx MOD NumOfColumns EQ 0 and idx NEQ UserIDCount>
            <cfset iCount=0>

I appreciate you taking the time to help me out with this.
Jester_48 Rocks!
glad i could help

thanks for teh points and the good word ;)