JohnMac328
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></s pan> <a href=""fund_divs_archive.a sp?tablena me=TableG" " class=""buttonbox"">TableG dividend archives</a><br /><br />") end if
The fund_divs_archive.asp?tabl ename=Tabl eG 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>Divide nd/Distrib ution Per Share</b></td><td align=""center""><b>Reinve st Price Per Share</b></td></tr>")
if tablename="TableG" then
response.write("<tr bgcolor=#ffffff class=bodytext1><td>" & monthname(recordset5.field s("date_pa id_month") ) & " " & recordset5.fields("date_pa id_year") & "</td><td align=right>" & recordset5.fields("dividen d") & "</td><td align=right>" & recordset5.fields("reinves t_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?tablen ame=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>Divide nd/Distrib ution 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_pa id_day#/
#date_paid_year#</td><td align=right>#dividend#</td ><td align=right>#reinvest_pric e#</td></t r>
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
if tablename="TableG" then response.write("<span class=body_text_bold2><a href=""URL"">TitleG</a></s
The fund_divs_archive.asp?tabl
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>Divide
if tablename="TableG" then
response.write("<tr bgcolor=#ffffff class=bodytext1><td>" & monthname(recordset5.field
The above code works. When I try to populate with this CF code
<cfif vTableName eq "TableG">
<span class="body_text_bold2"><a
<a href="fund_divs.cfm?tablen
<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>Divide
Reinvest Price Per Share</b></td></tr>
<tr bgcolor=##ffffff class=bodytext1><td>#date_
#date_paid_year#</td><td align=right>#dividend#</td
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
ASKER
What are the tags around the table since it is outside the cfoutput query?
ASKER
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.
ASKER
Ok thanks
ASKER
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>Divide nd/Distrib ution 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?vtable name=Table A" 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?vtable name=Table B" 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?tablen ame=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?tablen ame=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?tablen ame=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?tablen ame=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?vtable name=Table G" class="buttonbox">latest archive</a><br />
<br />
</cfif>
</cfoutput>
<tr bgcolor=##ffffff class=bodytext1><td>#date_ paid_month #/#date_pa id_day#/
#date_paid_year#</td><td align=right>#dividend#</td ><td align=right>#reinvest_pric e#</td></t r>
</table>
<table width=630 cellpadding=3 cellspacing=1 bgcolor=##efefef>
<tr bgcolor=##eeeeff class=style2><td><b>Date Paid</b></td><td align=""center""><b>Divide
Reinvest Price Per Share</b></td></tr>
<cfoutput query="getTableData">
<cfif vTableName eq "TableA">
<span class="body_text_bold2"><a
<a href="fund_divs.cfm?vtable
</cfif>
<cfif vTableName eq "TableB">
<span class="body_text_bold2"><a
<a href="fund_divs.cfm?vtable
</cfif>
<br />
<cfif vTableName eq "TableC">
<span class="body_text_bold2"><a
<a href="fund_divs.cfm?tablen
<br />
</cfif>
<cfif vTableName eq "TableD">
<span class="body_text_bold2"><a
<a href="fund_divs.cfm?tablen
<br />
</cfif>
<cfif vTableName eq "TableE">
<span class="body_text_bold2"><a
<a href="fund_divs.cfm?tablen
<br />
</cfif>
<cfif vTableName eq "TableF">
<span class="body_text_bold2"><a
<a href="fund_divs.cfm?tablen
<br />
</cfif>
<cfif vTableName eq "TableG">
<span class="body_text_bold2"><a
<a href="fund_divs.cfm?vtable
<br />
</cfif>
</cfoutput>
<tr bgcolor=##ffffff class=bodytext1><td>#date_
#date_paid_year#</td><td align=right>#dividend#</td
</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
(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>
ASKER
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">
<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?vtable name=Table A" 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
<cfoutput query="getTableData">
<cfif vTableName eq "TableA">
<span class="body_text_bold2"><a
<a href="fund_divs.cfm?vtable
</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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect, many thanks as usual.
Welcome :)
Sorry folks. I did not even see the new comment added by SidFishes's when I was replying...
ASKER
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
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
ASKER
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 ;-)
<table width=630 cellpadding=3 cellspacing=1 bgcolor="#efefef">
<tr bgcolor="#eeeeff" class="style2">
<td><b>Date Paid</b></td>
<td align=""center""><b>Divide
<td align=""center""><b>Reinve
</tr>
<cfoutput query="yourQuery">
<tr bgcolor=##ffffff class=bodytext1>
<td>#date_paid_month#/#dat
<td align=right>#dividend#</td
<td align=right>#reinvest_pric
</tr>
</cfoutput>
</table>