Solved

display query output in columns and rows

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

Accepted Solution

by:
dgrafx earned 250 total points
Comment Utility
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
Comment Utility

 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now