Solved

display query output in columns and rows

Posted on 2007-03-21
2
299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
What You Need to Know when Searching for a Webhost Provider
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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