Solved

display query output in columns and rows

Posted on 2007-03-21
2
296 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

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
website file permissions 4 77
Two nodes for updates and forwarding 8 51
Redundant SQL Servers Without Clustering 7 119
Problem to get function 52 111
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

765 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