Solved

display query output in columns and rows

Posted on 2007-03-21
2
295 Views
Last Modified: 2013-12-24
How can I display the output in a table so that it's 4 down with 3 rows across or 4 down with 4 rows across:

<cfset CurrentPage=GetFileFromPath(GetTemplatePath())>
<cfparam name="PageNum_myquery" default="1">
<cfquery name="myquery" datasource="dsn">
SELECT *
FROM listings
where status = 'active'
order by MyIdentity asc
</cfquery>
<cfset MaxRows_myquery=4>
<cfset StartRow_myquery=Min((PageNum_myquery-1)*MaxRows_myquery+1,Max(myquery.RecordCount,1))>
<cfset EndRow_myquery=Min(StartRow_myquery+MaxRows_myquery-1,myquery.RecordCount)>
<cfset TotalPages_myquery=Ceiling(myquery.RecordCount/MaxRows_myquery)>
<cfset QueryString_myquery=Iif(CGI.QUERY_STRING NEQ "",DE("&"&XMLFormat(CGI.QUERY_STRING)),DE(""))>
<cfset tempPos=ListContainsNoCase(QueryString_myquery,"PageNum_myquery=","&")>
<cfif tempPos NEQ 0>
  <cfset QueryString_myquery=ListDeleteAt(QueryString_myquery,tempPos,"&")>
</cfif>
<cfoutput query="myquery" startrow="#StartRow_myquery#" maxrows="#MaxRows_myquery#">#short_note#<!--- <img src="props/#photo_main#" width="648" height="6" border="" alt=""> ---><br><br></cfoutput>
0
Comment
Question by:COwebmaster
2 Comments
 
LVL 25

Accepted Solution

by:
dgrafx earned 250 total points
ID: 18770233
is this what you mean?
<TABLE>
<cfoutput query="myquery" startrow="#StartRow_myquery#" maxrows="#MaxRows_myquery#">
<cfif currentrow mod 3 is 1><tr></cfif>
      <td align="left">#short_note#<!--- <img src="props/#photo_main#" width="648" height="6" border="" alt=""> ---></td>
<cfif currentrow mod 3 is 0></tr></cfif>
</cfoutput>
</TABLE>

this will display 3 columns
just change the 3 to 4 to display 4 columns

0
 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 250 total points
ID: 18772894

 I think you mean for the values to go down first, the across?  Like this...

 1  5    9
 2  6   10
 3  7   11
 4  8

If so, this code will do it....

You need to replace "myQuery" with your query name and "ColumName" with the column you want to display.  Also, change the numColumns to how ever many you want across, the code will do the rest.

<cfset variables.NumColumns = 5>

<cfset variables.numberOfRows = ceiling(myQuery.recordCount/variables.NumColumns)>
<cfoutput>
Create Matrix: #variables.NumColumns# Cols x #variables.numberOfRows# Rows<br>
<table align="center" border="1">
 <cfloop index="RR" from="1" to="#variables.numberOfRows#">
   <TR>
   <cfloop index="CC" from="1" to="#variables.NumColumns#">
       <cfset variables.recordCounter = (variables.numberOfRows * (CC - 1)) + RR>
     <td>
       <cfif variables.recordCounter gt 0 and variables.recordCounter le myQuery.recordCount>
         <cfset variables.theValue = myQuery['ColumnName'][variables.recordCounter]>
         #variables.theValue#
       <cfelse>
         &nbsp;
       </cfif>
       </td>
   </cfloop>
   </tr>
 </cfloop>
 </tr>
</table>
</cfoutput>
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question