How about this? You can decide how many cols you have:

<cfoutput>
<cfif qMyQuery.recordCount>
<cfscript>
cols = 10; // you can change this to any nr of cols
rows = ((qMyQuery.recordCount - 1) \ cols) + 1;
</cfscript>
<table>
<cfloop index="i" from="1" to="#rows#">
        <tr>
        <cfloop index="j" from="1" to="#cols#">
                <cfset k = (i-1)*cols + j>
                <td>
                        <cfif k LTE qMyQuery.recordCount>
                                #qMyQuery.value[k]#
                        <cfelse>
                                &nbsp;
                        </cfif>
                </td>
        </cfloop>
        </tr>
</cfloop>
</table>
</cfif>
</cfoutput>

-----Original Message-----
From: Kay Smoljak [mailto:[EMAIL PROTECTED]]
Sent: donderdag 27 december 2001 4:24
To: CF-Talk
Subject: Re: How to display records next to each other - horizontally?


Stefan,

I haven't run the following code, so apologies in advance for any syntax
errors, but it shows the principle of what I do. Someone else might be
able to come up with something shorter and more efficient, but this
example explains what is going on. 

<!--- Build the table --->
<table border="0">
        <cfoutput query="myQuery">
        <~--- if it's not the last record --->
        <cfif myQuery.currentRow NEQ myQuery.RecordCount>
                <!--- check if it's odd or even --->
                <cfif myQuery.currentRow mod 2 NEQ 0>
                        <!--- it's odd, display a new row ---> 
                        <tr><td>#myQuery.value#</td>
                <cfelse>
                        <!--- it's even, end the row --->
                        <td>#myQuery.value#</td></tr>                   
                </cfif>
        <!--- if it is the last record --->
        <cfelse>
                <!--- check if it's odd or even --->
                <cfif myQuery.currentRow mod 2 NEQ 0>
                        <!--- it's odd, span the whole row --->
                        <tr><td>#myQuery.value#</td><td>&nbsp;</td></tr>
                <cfelse>
                        <!--- it's even, just finish the row as normal
--->
                        <td>#myQuery.value#</td></tr>
                </cfif>
        </cfif> 
        </cfoutput>
</table>

HTH,
Kay.


"stoem" <[EMAIL PROTECTED]> wrote in message
news:<[EMAIL PROTECTED]>...
> Hi everyone,
> I am trying to display a series of images the paths of which are held 
> in a database. This is easy as long as I want to display the images 
> one on top of the next but this way I lose a lot of screenspace.
> 
> What I want to to is to display the images in pairs inside a table: 
> first row > images one in <td> one and image two in <td> two, second 
> row > image three in <td> one and image four in <td> two and so on. I 
> also need to work around the fact that I might have 3, 5, 7 etc 
> results returned in which case the last row will only be filled with 
> one image...
> 
> I have a feeling that I need something along the lines of  MOD 2 but I

> don't know how to do it and where to start.
> 
> Thanks for any help,
> 
> Stefan
> 
> 
> 
> 
> 
> 

______________________________________________________________________
Get Your Own Dedicated Windows 2000 Server
  PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER
  Instant Activation � $99/Month � Free Setup
  http://www.pennyhost.com/redirect.cfm?adcode=coldfusionb
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to