6 Replies Latest reply on Mar 25, 2009 11:30 AM by Cooperstown.Com

    CFLoop problem

    Cooperstown.Com
      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.

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


        • 1. Re: CFLoop problem
          Dan Bracuk Level 5
          At first glance, it looks like an infinite loop. Why are you resetting rcount back to 0 when it equals 1?
          • 2. Re: CFLoop problem
            Cooperstown.Com Level 1
            So that is starts a new row...

            You can view it at the following page:

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

            • 3. Re: CFLoop problem
              Cooperstown.Com Level 1
              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
              • 4. Re: CFLoop problem
                Level 7
                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/
                • 5. Re: CFLoop problem
                  tclaremont Level 2
                  Great idea, Azadi. I just modified a few of my pages that I created years ago with that cleaner approach.
                  • 6. Re: CFLoop problem
                    Cooperstown.Com Level 1
                    Azadi thanks for your response, I updated my code and it works great.

                    Thanks again.