Link to home
Start Free TrialLog in
Avatar of JohnMac328
JohnMac328Flag for United States of America

asked on

Coldfusion CS3 - Title and table header fields repeating

I am trying to retrieve a selection of records to display in a table.  They table is populated with the data based on which  link is clicked.  The link is a table that is passed with a url parameter.  The problem is the titles and headers are repeating where I just want the rows of records displayed and the title and headers of the table displayed only once.  This is a conversion from asp to coldfusion.  It works correctly with asp but does not with CF in the current config.  Here is the asp code

if tablename="TableG" then response.write("<span class=body_text_bold2><a href=""URL"">TitleG</a></span>&nbsp;<a href=""fund_divs_archive.asp?tablename=TableG"" class=""buttonbox"">TableG dividend archives</a><br /><br />") end if

The fund_divs_archive.asp?tablename=TableG link when clicked populates this table

response.write("<table width=630 cellpadding=3 cellspacing=1 bgcolor=#efefef>")
response.write("<tr bgcolor=#eeeeff class=style2><td><b>Date Paid</b></td><td align=""center""><b>Dividend/Distribution Per Share</b></td><td align=""center""><b>Reinvest Price Per Share</b></td></tr>")

if tablename="TableG" then
response.write("<tr bgcolor=#ffffff class=bodytext1><td>" & monthname(recordset5.fields("date_paid_month")) & " " & recordset5.fields("date_paid_year") & "</td><td align=right>" & recordset5.fields("dividend") & "</td><td align=right>" & recordset5.fields("reinvest_price") & "</td></tr>")

The above code works.  When I try to populate with this CF code

<cfif vTableName eq "TableG">
<span class="body_text_bold2"><a href="URL">TableG title</a></span>
<a href="fund_divs.cfm?tablename=TableG" class="buttonbox">TableG dividend archives</a><br />
<br />

<table width=630 cellpadding=3 cellspacing=1 bgcolor=##efefef>
 <tr bgcolor=##eeeeff class=style2><td><b>Date Paid</b></td><td align=""center""><b>Dividend/Distribution Per Share</b></td><td align=""center""><b>
Reinvest Price Per Share</b></td></tr>

<tr bgcolor=##ffffff class=bodytext1><td>#date_paid_month#/#date_paid_day#/
#date_paid_year#</td><td align=right>#dividend#</td><td align=right>#reinvest_price#</td></tr>


The TableG title repeats and the table headers such as "Date Paid" also repeat.  I just want the TableG title to display once and the table header titles to display once followed by the records of course

Hope this was not too confusing.  Any help appreciated.

John
Avatar of _agx_
_agx_
Flag of United States of America image

Is it possible you have the headers inside a <cfoutput query="..."> loop ?  That would cause the headers to repeat.  I think what you're looking for is something like this.  Note, the headers are outside the cfoutput loop.

<table width=630 cellpadding=3 cellspacing=1 bgcolor="#efefef">
 <tr bgcolor="#eeeeff" class="style2">
       <td><b>Date Paid</b></td>
      <td align=""center""><b>Dividend/Distribution Per Share</b></td>
      <td align=""center""><b>Reinvest Price Per Share</b></td>
</tr>
<cfoutput query="yourQuery">
<tr bgcolor=##ffffff class=bodytext1>
      <td>#date_paid_month#/#date_paid_day#/#date_paid_year#</td>
      <td align=right>#dividend#</td>
      <td align=right>#reinvest_price#</td>
</tr>
</cfoutput>
</table>


Avatar of JohnMac328

ASKER

What are the tags around the table since it is outside the cfoutput query?
Nevermind the last comment, still have repeating URL links with strange data, may have to pick this up tomorrow
Okay.  I suspect it is related to the positioning of the <cfoutput> tags.  But tomorrow just post the full code, so we can have a better idea of where it is going wrong.
Ok thanks
This should show enough to get the display to work correctly.

<table width=630 cellpadding=3 cellspacing=1 bgcolor=##efefef>
 <tr bgcolor=##eeeeff class=style2><td><b>Date Paid</b></td><td align=""center""><b>Dividend/Distribution Per Share</b></td><td align=""center""><b>
Reinvest Price Per Share</b></td></tr>

<cfoutput query="getTableData">
<cfif vTableName eq "TableA">
<span class="body_text_bold2"><a href="URL">TableA title</a></span>
<a href="fund_divs.cfm?vtablename=TableA" class="buttonbox">latest archive</a><br /><br />
</cfif>
<cfif vTableName eq "TableB">
 <span class="body_text_bold2"><a href="URL">TableB title</a></span>
 <a href="fund_divs.cfm?vtablename=TableB" class="buttonbox">latest archive</a><br />
</cfif>
<br />

<cfif vTableName eq "TableC">
<span class="body_text_bold2"><a href="URL">TableC title</a></span>
<a href="fund_divs.cfm?tablename=TableC" class="buttonbox">latest archive</a><br />
<br />
</cfif>
<cfif vTableName eq "TableD">
<span class="body_text_bold2"><a href="URL">TableD title</a></span>
<a href="fund_divs.cfm?tablename=TableD" class="buttonbox">latest archive</a><br />
<br />
</cfif>
<cfif vTableName eq "TableE">
<span class="body_text_bold2"><a href="URL">TableE title</a></span>
<a href="fund_divs.cfm?tablename=TableE" class="buttonbox">latest archive</a><br />
<br />
</cfif>
<cfif vTableName eq "TableF">
<span class="body_text_bold2"><a href="URL">TableF title</a></span>
<a href="fund_divs.cfm?tablename=TableF" class="buttonbox">latest archive</a><br />
<br />
</cfif>
<cfif vTableName eq "TableG">
<span class="body_text_bold2"><a href="URL">TableG title</a></span>
<a href="fund_divs.cfm?vtablename=TableG" class="buttonbox">latest archive</a><br />
<br />
</cfif>
</cfoutput>
<tr bgcolor=##ffffff class=bodytext1><td>#date_paid_month#/#date_paid_day#/
#date_paid_year#</td><td align=right>#dividend#</td><td align=right>#reinvest_price#</td></tr>
</table>
there's a bunch of issues with html, tables and things here but first try this in a test.cfm page

(no other code) and tell us if this is the layout you are looking for
<cfset getTableData = querynew("")>
 
<cfset queryaddcolumn  (getTableData, "TableName", "CF_SQL_integer", ListToArray("TableA, TableB, TableC, TableD, TableE,TableF, TableG  "))>
<cfset queryaddcolumn  (getTableData, "TableTitle", "cf_sql_varchar", ListToArray("here, there, everywhere, nowhere, anywhere,somewhere, Foo, Bar"))> 
 <CFSET date_paid_month = 10>
<CFSET date_paid_day = 21>
<CFSET date_paid_year = 90>
<CFSET DIVIDEND = "$1">
<cfset reinvest_price = "$3"> 
 
 
<table width="630" cellpadding="3" cellspacing="1" bgcolor="#efefef">
 <tr bgcolor="#eeeeff" class="style2"><td><b>Date Paid</b></td><td align="center">
	<b>Dividend/Distribution Per Share</b></td>
	<td align="center"><b>
Reinvest Price Per Share</b></td></tr>
<cfoutput query="getTableData">
<tr><td colspan="3">
<span class="body_text_bold2"><a href="URL">#tableTitle#</a></span>
<a href="fund_divs.cfm?vtablename=#TableName#" class="buttonbox">latest archive</a><br /><br />
 
</td></tr>
<tr bgcolor"##ffffff" class="bodytext1"><td>#date_paid_month# / #date_paid_day#/
#date_paid_year#</td><td align="right">#dividend#</td><td align="right">#reinvest_price#</td></tr></cfoutput>
</table>

Open in new window

That is the correct layout but this info is being pulled from the database, not defined here

<CFSET date_paid_month = 10>
<CFSET date_paid_day = 21>
<CFSET date_paid_year = 90>
<CFSET DIVIDEND = "$1">
<cfset reinvest_price = "$3">
The problem is the placement of the <cfoutput query=".."> tags.  Anything inside those tags will be repeated once, for _each_ row in the query.  That's why the headers are being repeated.  

     <cfoutput query="getTableData">
    <cfif vTableName eq "TableA">
        <span class="body_text_bold2"><a href="URL">TableA title</a></span>
         <a href="fund_divs.cfm?vtablename=TableA" class="buttonbox">latest archive</a><br /><br />
     </cfif>
    ....
    </cfoutput>

Since your headers do not contain any CF variables, you do not need to use any cfoutput tags around them at all.  Typically, you only need to use <cfoutput> tags when you're trying to output the value of a #variable# or a cfquery.  Try this



<table width=630 cellpadding=3 cellspacing=1 bgcolor=#efefef>
 <tr bgcolor=#eeeeff class=style2><td><b>Date Paid</b></td><td align=""center""><b>Dividend/Distribution Per Share</b></td><td align=""center""><b>
Reinvest Price Per Share</b></td></tr>
 
<!--- do not use any cfoutput tags here --->
<cfif vTableName eq "TableA">
<span class="body_text_bold2"><a href="URL">TableA title</a></span>
<a href="fund_divs.cfm?vtablename=TableA" class="buttonbox">latest archive</a><br /><br />
</cfif>
<cfif vTableName eq "TableB">
 <span class="body_text_bold2"><a href="URL">TableB title</a></span>
 <a href="fund_divs.cfm?vtablename=TableB" class="buttonbox">latest archive</a><br />
</cfif>
<br />
 
<cfif vTableName eq "TableC">
<span class="body_text_bold2"><a href="URL">TableC title</a></span>
<a href="fund_divs.cfm?tablename=TableC" class="buttonbox">latest archive</a><br />
<br />
</cfif>
<cfif vTableName eq "TableD">
<span class="body_text_bold2"><a href="URL">TableD title</a></span>
<a href="fund_divs.cfm?tablename=TableD" class="buttonbox">latest archive</a><br />
<br />
</cfif>
<cfif vTableName eq "TableE">
<span class="body_text_bold2"><a href="URL">TableE title</a></span>
<a href="fund_divs.cfm?tablename=TableE" class="buttonbox">latest archive</a><br />
<br />
</cfif>
<cfif vTableName eq "TableF">
<span class="body_text_bold2"><a href="URL">TableF title</a></span>
<a href="fund_divs.cfm?tablename=TableF" class="buttonbox">latest archive</a><br />
<br />
</cfif>
<cfif vTableName eq "TableG">
<span class="body_text_bold2"><a href="URL">TableG title</a></span>
<a href="fund_divs.cfm?vtablename=TableG" class="buttonbox">latest archive</a><br />
<br />
</cfif>
 
<!--- put the cfoutput query around the query data columns you are trying to display  --->
<!--- I am assuming date_paid_month, etc are columns in your query --->
<cfoutput query="getTableData">
<tr bgcolor=##ffffff class=bodytext1><td>#date_paid_month#/#date_paid_day#/
#date_paid_year#</td><td align=right>#dividend#</td><td align=right>#reinvest_price#</td></tr>
</table>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect, many thanks as usual.  
Welcome :)
Sorry folks.  I did not even see the new comment added by SidFishes's when I was replying...
Oh, wow, I never noticed the different name.  Many thanks SidFishes for your help
not a problem (but i get to lecture you now ;>)

valid html requires that html tag attributes be enclosed in "" ie <td bgcolor="#FFFFFF">
and for that matter since you are using at least css classes, you might consider using css rather than tag attributes

ie:

<td style="text-align:center;">

this is the preferred way as mixing tag attributes and css can have unexpected results

lastly, remember that you only need to escape # when it is enclose in a cf tag. The code in your original post

<table width=630 cellpadding=3 cellspacing=1 bgcolor=##efefef>

produces a most hideous shade of blue (apologies if its part of your corporate identity (sympathies too ;)

browsers are confused when they see the ## since it is not stripped by CF and turned into # which is what they expect for a color


You are correct about the color, and no it is not the intended color :).  I appreciate your suggestions and will use them.
ROFL - SidFishes all valid points (and funny too ;-)