Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Handling empty table cells when grouping

Status
Not open for further replies.

keneck

Programmer
Nov 26, 2002
23
US
Hello,
I'm having a problem finding a way to handle the display of a complex table when some cells have no data.

I have a query that returns a variable number of advertising records for each Content ID value. I am displaying the data inside a table that uses the group attribute for cfoutput to produce a single row for each Content ID value. For example, the first Content ID has 3 items in cells 1 and 2 and then 2 items in cell three. This is fine until there are no items at all in a particular cell. Then the cell is empty and the cell doesn't display. The table looks broken and I haven't found a way to stick a non-breaking space inside the cell to fix the problem.

The problem is similar to what would happen if you were outputing query data in multiple columns and the total number of rows wasn't evenly divisble by the number of columns. If I have 14 records in 3 columns, the last row will only have 2 cells instead of 3 and that last cell doesn't get created unless you write code to accommodate that. I'm not sure this can be done on a row by row basis when I'm grouping data.

Here is the code to produce the current results:

<cfoutput query="getContentAds" group="Menu1ID">
<table border="1" cellspacing="0" cellpadding="2" align="left">
<tr>
<th colspan="8" align="left">#UCase(Level1Name)#</th>
</tr>
<tr>
<th align="center">Item ID</th>
<th align="center">Menu 1</th>
<th align="center">Menu 2</th>
<th align="center">Menu 3</th>
<th align="center">Title</th>
<th align="center">Top 1</th>
<th align="center">Top 2</th>
<th align="center">Top 3</th>
</tr>
<cfoutput group="contentID">
<tr>
<td align="center" valign="top">#ContentID#</td>
<td align="center" valign="top">#Level1Name#</td>
<td align="center" valign="top"><cfif #Level2Name# IS NOT "">
#Level2Name#<cfelse>NA</cfif></td>
<td align="center" valign="top"><cfif #Level3Name# IS NOT "">#Level3Name#<cfelse>NA</cfif></td>
<td align="center" valign="top">#Title#</td>
<cfoutput group="Position_Order">
<td align="center" valign="top"><cfoutput group="AdBankID">
<cfset adList = "">
<cfoutput>
<!--- first determine whether there are any items in the list for this table cell --->
<cfif NOT #ListContains(adList, getContentAds.AdID[currentrow])#>
<cfset adList = #ListAppend(adList, getContentAds.AdID[currentrow])#>
</cfif>
</cfoutput>
#adList#</td>
</cfoutput>
<!--- once the position order changes, we move to a new cell --->
</cfoutput>
</tr>
<!--- when the content ID changes we move to a new row --->
</cfoutput>
</table>
<!--- when the menu category changes we move to a new table --->
</cfoutput>

The resulting table with data looks like this:
<table cellpadding="2" cellspacing="0" border="1">
<tr>
<th colspan="8" align="left">NEWS</th></tr>
<tr>
<th align="center">Item ID</th>
<th align="center">Menu 1</th>
<th align="center">Menu 2</th>
<th align="center">Menu 3</th>
<th align="center">Title</th>
<th align="center">Top 1</th>
<th align="center">Top 2</th>
<th align="center">Top 3</th>
</tr>
<tr>
<td align="center">355</td>
<td align="center">News</td>
<td align="center">NA</td>
<td align="center">NA</td>
<td align="center">First Test</td>
<td align="center">10, 12, 13</td>
<td align="center">14, 15, 16</td>
<td align="center">6, 9</td>
</tr>
<tr>
<td align="center">384</td>
<td align="center">News</td>
<td align="center">Sports</td>
<td align="center">Basketball</td>
<td align="center">Second Test</td>
<td align="center">10</td>
<td align="center">10</td>
<td align="center">6, 9</td>
</tr>
</table>

This is fine except that it assumes there is data for all cells in each row. I need to be able to create all table cells on each row even when one or more of them have no content. When a table cell is empty, the grouping process moves to the next cell or next row and leaves the table incomplete or unbalanced.

Maybe there is no practical way to handle this and I should try another approach, but I didn't want to give up before checking to see if anybody else had an idea.
 
use a <br> after all of you content.

<td>
#dynamicStuffThatMayBeEmpty#<br>
</td>

this will give you some content in the cell when there is nothing there, and will look the same if there is data.

</td>
stuff</br>
</td>
<td>
<br>
</td>

thereptilian120x120.gif
 
Bombboy
Thanks for taking the time to respond. I found the solution to my problem by following a different route altogether.

The situation required creating a structure for each record and placing all of these structures inside a one dimensional array. Then the table was created using two loops.
The first loop went through each content item and created a new row whenever that changed. Within a row, I used a second loop to build a list of items for each potential cell in the table. Each table cell was then created based on the content of the list for that cell. If the list had items, the list was placed in the cell. If the list was empty, the cell was created with a nonbreaking space. It was even possible to determine whether two cells should be merged by comparing the list for cell one with the list for cell two. If they were the same, the two cells were merged. Otherwise they were created separately.

This situation was extremely difficult to describe and this is the only forum where I was even able to get a response. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top