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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFOUTPUT & Columns

Status
Not open for further replies.

riluve

Technical User
Mar 11, 2005
78
US
Try as I might, I can't figure this one out. Here is my simple implementation which is not exactly what I want.

<CFQUERY NAME="TEST" DATASOURCE="DB">
SELECT *
`Data` AS DATA,
`Catagory` AS CAT
FROM `TABLE`
</CFQUERY>
<table width="200" >
<CFOUTPUT QUERY= "TEST">
<tr>
<td>#HTTP#</td>
</tr>
</CFOUTPUT>
</table>

Of course this gives me one long colum. What I would like to do is place the 'DATA'in seperate columns in the output table based on the Catagory. So the output should look like this:

Cat1 Cat2 Cat3
DATA DATA DATA
DATA DATA DATA
DATA DATA DATA

Where should I start? In the SQL or the CFOUTPUT tag?

 
oopps, sorry, small mistake, here is a better updated example:

<CFQUERY NAME="TEST" DATASOURCE="DB">
SELECT *
`Data` AS DATA,
`Catagory` AS CAT
FROM `TABLE`
</CFQUERY>
<table width="200" >
<CFOUTPUT QUERY= "TEST">
<tr>
<td>#DATA#</td>
</tr>
</CFOUTPUT>
</table>
 
Try This

Code:
<CFQUERY NAME="TEST" DATASOURCE="DB">
    SELECT *
    `Data` AS DATA,
    `Catagory` AS CAT
    FROM `TABLE`
</CFQUERY>
<table width="200" >
<CFOUTPUT QUERY= "TEST">
    <tr>
    <td>#DATA#</td>
    <CFIF TEST.CurrentRow MOD 3 IS 0>
           </TR>    <TR>                                </tr></CFIF></CFOUTPUT>
</table>
 
But what happens if your last row only has 2 records? Then you won't have a closing <tr> tag, which is invalid HTML, and can actually cause the page not to display at all in some browsers. (BTW, in your example you close the <tr>, then open it but immediately close it agin without any <td> tags...)

This is what you need:
Code:
<table>
  <!--- Keeps track of the current number of TD cells displayed --->
  <cfset iCount = 0>
  <!--- Set this to the number of TD cells you want displayed --->
  <cfset tCount = 2>
  <cfoutput query="TEST">
     <cfset icount = icount+1>
     <cfif icount eq 1>
        <tr>
     </cfif>
     <td>#DATA#</td>
     <cfif icount eq tCount>
       <cfset icount = 0>
       </tr>
     </cfif>
  </cfoutput>
  <!--- Includes however many blank TD tags are needed to finish out and close the current TR --->
  <cfif icount NEQ tCount AND icount GT 0>
    <cfloop condition="icount LT tCount">
      <cfset icount = icount+1>
      <td>&nbsp;</td>
    </cfloop>
    </tr>
  </cfif>
</table>

Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
check the links I posted, the one with the grouped results.

look over the other ones too, to get an idea of the html flow

my grouped output example does what you are talking about, but is made for lots more groups, so it runs in rows. if you only have 3 columns (GROUPS) than it will do what you want, modify it and make it yours.

Kevin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top