Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

display query output in columns and rows

Posted on 2007-03-21
2
Medium Priority
?
301 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 1000 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 1000 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

Simple, centralized multimedia control

Watch and learn to see how ATEN provided an easy and effective way for three jointly-owned pubs to control the 60 televisions located across their three venues utilizing the ATEN Control System, Modular Matrix Switch and HDBaseT extenders.

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…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

670 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