Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Split up cfquery results

Participant ,
Sep 16, 2008 Sep 16, 2008
Hello. I am querying my database and usually the resultset contains about 100 records. I want to split up my results dynamically into three columns instead of just listing them out like I currently do. I am not sure how to do this. This is pretty generic but is the format I'm currently using...

<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>

<!--- Get and return related waters --->
<cfquery name="query" datasource="myds">
SELECT id FROM my_db WHERE state = '#state#'
</cfquery>

<cfoutput query="query">
#id#<br>
</cfoutput>

</td>
</tr>
</table>


I want to have it so when the result row is 40, create a new column and display the next 40 results, and so on.

Can someone please help?

Thanks!
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 17, 2008 Sep 17, 2008
do something like:

<!--- Get and return related waters --->
<cfquery name="query" datasource="myds">
SELECT id FROM my_db WHERE state = '#state#'
</cfquery>

<cfset maxRow = 40> <!--- set the maximum row of table to be displayed --->

<!--- Get the number of columns(noOfCol) to accomodate all data --->
<cfset noOfCol = query.recordcount\maxRow>
<cfif query.recordcount Mod maxRow neq 0>
<cfset noOfCol = noOfCol + 1>
</cfif>

<table width="100%" cellpadding="0" cellspacing="0" border="1">
<cfloop from="1" to="#maxRow#" index="nRow">
<cfset nDataRow = nRow> <!--- initialize to current row --->
<tr>
<cfloop from="1" to="#noOfCol#" index="i">
<td><cfoutput>#query.id[nDataRow]#</cfoutput></td>
<cfset nDataRow = nDataRow + maxRow>
</cfloop>
</tr>
</cfloop>
</table>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 17, 2008 Sep 17, 2008
LATEST
Works great! Thank you.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources