Skip to main content
March 23, 2009
Answered

CFLoop problem

  • March 23, 2009
  • 6 replies
  • 537 views
Hi,

I am trying to populate a two column table with data from my database from left to right.

I have it almost working except that the same customer fills both columns and the code creates the next row and does the same thing with the next record… this happens with all of the records from the query.

You can view the page at the following URL: http://test.cooperstown.com/attractions.cfm.

--------------------------------------------------------------------


This topic has been closed for replies.
Correct answer Newsgroup_User
here's a better approach: use MOD operator to check if current query row
is odd or even - if even insert your </tr><tr> to start new row. no need
for extra rowcount variable:

<div id="listTable">
<table summary="Attractions">
<caption>Attractions</caption>
<tbody>
<tr>
<cfoutput query="getListingInfo">
<td>
<strong class="custName">#getListingInfo.BName#<br />
#getListingInfo.City#, #getListingInfo.State#, #getListingInfo.Zip#<br
/> #getListingInfo.PhoneNum#<br />
<cfif getListingInfo.Link is "Y">
<a href="mailto:#getListingInfo.Email#?subject=Cooperstown Family
Guide,&bcc=info@cooperstown.com">#getListingInfo.Email#</a><br />
<a href="#getListingInfo.URL#"
target="_blank">#getListingInfo.BName# Web Site</a>
</cfif>
</td>
<cfif getListingInfo.currentrow LT getListingInfo.recordcount AND
getListingInfo.currentrow MOD 2 is 0>
</tr><tr>
</cfif>
</cfoutput>
</tr>
</tbody>
</table>
</div>

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/

6 replies

March 25, 2009
Azadi thanks for your response, I updated my code and it works great.

Thanks again.

tclaremont
Inspiring
March 25, 2009
Great idea, Azadi. I just modified a few of my pages that I created years ago with that cleaner approach.
Newsgroup_UserCorrect answer
Inspiring
March 24, 2009
here's a better approach: use MOD operator to check if current query row
is odd or even - if even insert your </tr><tr> to start new row. no need
for extra rowcount variable:

<div id="listTable">
<table summary="Attractions">
<caption>Attractions</caption>
<tbody>
<tr>
<cfoutput query="getListingInfo">
<td>
<strong class="custName">#getListingInfo.BName#<br />
#getListingInfo.City#, #getListingInfo.State#, #getListingInfo.Zip#<br
/> #getListingInfo.PhoneNum#<br />
<cfif getListingInfo.Link is "Y">
<a href="mailto:#getListingInfo.Email#?subject=Cooperstown Family
Guide,&bcc=info@cooperstown.com">#getListingInfo.Email#</a><br />
<a href="#getListingInfo.URL#"
target="_blank">#getListingInfo.BName# Web Site</a>
</cfif>
</td>
<cfif getListingInfo.currentrow LT getListingInfo.recordcount AND
getListingInfo.currentrow MOD 2 is 0>
</tr><tr>
</cfif>
</cfoutput>
</tr>
</tbody>
</table>
</div>

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
March 24, 2009
I got it to work! I had the <tr> tag inside the loop and it should have been just below the <tbody> tag.

The code below works:

<div id="listTable">
<table summary="Attractions">
<caption>Attractions</caption>
<tbody>
<tr>
<cfset rcount = 1>
<cfoutput query="getListingInfo">
<td>
<strong class="custName">#getListingInfo.BName#</strong><br />
#getListingInfo.City#, #getListingInfo.State#, #getListingInfo.Zip#<br />
#getListingInfo.PhoneNum#<br />
<cfif #getListingInfo.Link# is "Y">
<a href="mailto:#getListingInfo.Email#?subject=Cooperstown Family Guide,&bcc=info@cooperstown.com">#getListingInfo.Email#</a><br />
<a href="#getListingInfo.URL#" target="_blank">#getListingInfo.BName# Web Site</a>
</cfif>
</td>
<cfif rcount EQ 2>
</tr>
<cfset rcount = 1>
<cfelse>
<cfset rcount = rcount + 1>
</cfif>
</cfoutput>
</tbody>
</table>
</div>

----------------------------------------------------------

http://test.cooperstown.com/attractions.cfm

Thanks,

Nick
March 23, 2009
So that is starts a new row...

You can view it at the following page:

http://test.cooperstown.com/attractions.cfm

Inspiring
March 23, 2009
At first glance, it looks like an infinite loop. Why are you resetting rcount back to 0 when it equals 1?