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

CFLoop problem

Guest
Mar 23, 2009 Mar 23, 2009

Copy link to clipboard

Copied

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.

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


TOPICS
Advanced techniques

Views

435

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

LEGEND , Mar 23, 2009 Mar 23, 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...

Votes

Translate

Translate
LEGEND ,
Mar 23, 2009 Mar 23, 2009

Copy link to clipboard

Copied

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

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
Guest
Mar 23, 2009 Mar 23, 2009

Copy link to clipboard

Copied

So that is starts a new row...

You can view it at the following page:

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

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
Guest
Mar 23, 2009 Mar 23, 2009

Copy link to clipboard

Copied

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

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
LEGEND ,
Mar 23, 2009 Mar 23, 2009

Copy link to clipboard

Copied

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/

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 ,
Mar 25, 2009 Mar 25, 2009

Copy link to clipboard

Copied

Great idea, Azadi. I just modified a few of my pages that I created years ago with that cleaner approach.

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
Guest
Mar 25, 2009 Mar 25, 2009

Copy link to clipboard

Copied

LATEST
Azadi thanks for your response, I updated my code and it works great.

Thanks again.

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