|
Here is a way you can do this:
I will assume that you may not always get 20 or more records and that you
would always like to split the results into 2 columns (if this is not correct, I
think you will see how to do this easily):
// Set a variable to an integer value of 1/2
the size of your result set
<cfset rows=Int(getmachines.recordcount/2)>
// this sets rows equal to 1/2 of the number or records
returned
// Now set up a loop to go through the records set
using the rows variable as the upper limit
<cfloop index="x" from=1 to="#variables.rows#"
step="1">
<tr>
// display the field from the record set indexed by the
variable
// this causes the field you want to be displayed from
the record number of the index x to be used
// because CF stores your record set in a series of
arrays (one for each column) thus you will be
// displaying the entry from the database column for
the record number that is equal to the index x
<td>#getmachines.field[x]#</td>
// we will display the records for the second
column
// we will use the an index of rows+x (thus in your
case if we had 22 records we want the 21st
// record to be the first entry in your second table
column. Therefore the value of rows will be 20
// Now you want to set a variable with the value of
rows + the value of your index x
<cfset col2=rows+x>
// now before you display this value for this field,
you must test to make sure that you have
// not exceeded the number of records
<td>
<cfif col2 LT getmachine.recordcount>
#getmachine.field[col2]# //
display the value for record number indexed by col2 which will be equal
to (rows + x)
<cfelse>
<br> // else display a break so
that this blank table cell has a border also.
</td>
</cfloop>
The key to all this is the fact that CF stores the
result set in arrays with the column name from the
database as the array name. Therefore, to pull a value for a column for
any given record, you can use the record number as an index to the
array.
Hope all this makes sense to you because it becomes
very easy. You could use this same principle to display you result set in
any number of columns you would like. I have used this on several pages
and it really worked well.
On Sat, 05 May 2001 12:34:47 -0500 The Hepburn's <[EMAIL PROTECTED]> writes:
> I am trying to populate a table from a query but I want record sets > 1-20 on > the left side, results 21-xx next to it and so on. I thought this > would be > easy but am having a hard time getting it to work. Code is below. > Any > ideas? > > <cfif #form.machinegroup# is ""> > <cfquery name="getmachines" datasource="#def_SQLSource#" > dbtype="ODBC" > username="#def_SQLNameHistory#" password="#def_SQLPassHistory#"> > Select MachineName, machinegroup > From MachineData > Order by machineName > </cfquery> > <cfelse> > > <cfquery name="getmachines" datasource="#def_SqlSource#" > dbtype="ODBC" > username="#def_SQLNameHistory#" password="#def_SQLPassHistory#"> > Select * > From MachineData > Where machinegroup Like '#form.machinegroup#%' > </cfquery></cfif> > > > <table align="center" bgcolor="#B0D0CF" cellspacing="2" > cellpadding="2" > border="5" frame="box"> > <tr> > <cfoutput query="getmachinecount"> > <td>There are currently <font > color="FF0000"><B>#machinecount#</B></font> Workstations for this > SMS > Machine Group</td></tr></td> > </tr> > </table><TABLE border> > <tr></cfoutput> > <table> > <cfoutput query="getmachines" startrow=1 maxrows=5> > <TR><td width="5" colspan="4" rowspan="4">#Machinename#<br></td><td > width="5" colspan="4" > rowspan="4">#Machinegroup#<br></td></cfoutput> > <cfoutput query="getmachines" startrow=6 maxrows=10><td > width="5">#Machinename#<br></td><td > width="5">#Machinegroup#<br></td></cfoutput> > </tr> > > > > > ------------------------------------------------------------------------- > This email server is running an evaluation copy of the MailShield > anti- > spam software. Please contact your email administrator if you have > any > questions about this message. MailShield product info: > www.mailshield.com > > ----------------------------------------------- > To post, send email to [EMAIL PROTECTED] > To subscribe / unsubscribe: http://www.dfwcfug.org > |
- Populating a table from a query The Hepburn's
- Re: Populating a table from a query Palyne Gaenir
- Dave Cahall
