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

problems getting cfloop to output in 2 columns.

Contributor ,
Jan 28, 2010 Jan 28, 2010

Copy link to clipboard

Copied

Hello;

I'm having a problem making my code actually output properly. It's not throwing any errors, it actually says there is a record to be read, but my output from my cfloop is wrong I believe. I'm trying to make it break down into 2 columns like this

1 2

3 4

NEXT >

once there is 4 records, the button to go to next page comes up. I know this code is bulky, AI also know my query and next n buttons work fine, so I'm going to post just the query, and the loop with the statements to break it down into 2 columns.

Code:

<cfquery name="newsStory" datasource="#APPLICATION.dataSource#" maxRows=10>
SELECT klNews.title AS ViewField2, klNews.newsDate AS ViewField3, klNews.MYFile, klNews.MYFile2, klNews.ID AS ID
FROM klNews
    ORDER BY newsDate
</cfquery>

<cfset halfrecords = newsStory.RecordCount/2>

<cfloop query="newsStory" startRow="#URL.startRow#" endRow="#endRow#">
<cfoutput>
   <tr>
<cfif CurrentRow lte halfrecords>

<td width="49%" align="center" valign="top">

#All my content is in here for column 1#

</td>
</cfif>
<cfif Evaluate(CurrentRow+halfrecords) lte newsStory.RecordCount>
<td width="2%" align="center" valign="top">  </td>
<td width="49%" align="center" valign="top">

#column 2 stuff is here#

</cfif>
</tr>
</cfoutput></cfloop>

it's not showing anything at the moment,
Thank you.

TOPICS
Advanced techniques

Views

1.3K

Translate

Translate

Report

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

correct answers 1 Correct answer

Engaged , Jan 28, 2010 Jan 28, 2010

NOTE: small edit to fix a missing TD and url scope in what I just posted.

Might be missing some issue here, but seems like this sort of thing should work just fine.

<!--- default the start row from query to 1 --->

<cfparam default="1" name"url.startrow" />

<cfset newstartrow = url.startrow + 4 />

<!--- make counter to see if we close the tr --->

<cfset closecounter = 0 />

<cfoutput query="yourquery" startrow="#url.startrow#" maxrows="4">

<!--- check to see if odd or even --->

<cfif yourquery.currentrow M

...

Votes

Translate

Translate
LEGEND ,
Jan 28, 2010 Jan 28, 2010

Copy link to clipboard

Copied

<cfoutput query="yourquery">

#data#

<cfif currentrow mod the_number_of_records_per_row is 0>

start a new row.

Votes

Translate

Translate

Report

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
Contributor ,
Jan 28, 2010 Jan 28, 2010

Copy link to clipboard

Copied

that doesn't work, I tried it already. I have a next n button on this query. If i run the query on it's own, it works, when I add the startrow and maxrow it crashes.

How would I write this so I could hold 4 records a page with a next n working..

Just using cfloop query and no start row and max row in it doesn't work, just tried. it's somethign in the cfloop I think and the columns, it doesn't like each other. Is there a better way?

Votes

Translate

Translate

Report

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
Engaged ,
Jan 28, 2010 Jan 28, 2010

Copy link to clipboard

Copied

NOTE: small edit to fix a missing TD and url scope in what I just posted.

Might be missing some issue here, but seems like this sort of thing should work just fine.

<!--- default the start row from query to 1 --->

<cfparam default="1" name"url.startrow" />

<cfset newstartrow = url.startrow + 4 />

<!--- make counter to see if we close the tr --->

<cfset closecounter = 0 />

<cfoutput query="yourquery" startrow="#url.startrow#" maxrows="4">

<!--- check to see if odd or even --->

<cfif yourquery.currentrow MOD 2 eq 1>

<tr>

<td>#data#</td>

<cfset closecounter = 0 />

<cfelse>

<td>#data#</td>

</tr>

<cfset closecounter = 1 />

</cfif>

</cfoutput>

<!--- now we see if that last tr was actually closed in case we had odd number of final results --->

<cfif closecounter eq 0>

<td></td>

</tr>

</cfif>

<!--- next link adding 4 to the start row --->

<a href="blah.cfm?startrow=#newstartrow#">NEXT</a>

Votes

Translate

Translate

Report

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
Contributor ,
Jan 28, 2010 Jan 28, 2010

Copy link to clipboard

Copied

LATEST

thank you! That worked.

Votes

Translate

Translate

Report

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
Community Expert ,
Jan 28, 2010 Jan 28, 2010

Copy link to clipboard

Copied

It just might be the effect of the startRow and endRow. To test that, replace the line

<cfloop query="newsStory" startRow="#URL.startRow#" endRow="#endRow#">

with the line

<cfloop query="newsStory">

Votes

Translate

Translate

Report

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
Documentation