[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Loop (Help Please)

Posted on 2011-05-02
5
Medium Priority
?
300 Views
Last Modified: 2012-05-11
Hi,
I have menu and submenu database driven.  
I need to loop thru the submenu and display 15 records on each page.
after each 5 records I want to have a <br> tag.
here's what I have so far the main menu works fine but he submenu will
loop correctly.
 
<tr>
   <td colspan="2" >
     <div id="dolphincontainer">
     <div id="dolphinnav">
     <ul>					
     <cfloop query = "DispMainMenu"> 
        <li><cfoutput><a href="#MainMenuURL#" rel="#RelIDMainMenu#"><span>#MainMenuName#</span></a></cfoutput></li>					</cfloop>
      </ul>
      </div>
     <div id="dolphin_inner">
     <cfloop query = "DispSubMenu">
     <div id="<cfoutput>#DivID#</cfoutput>" class="innercontent"> 
						 
 // here I should have a loop to display the menu based on the div ID
						 
						  <cfloop index="i" from="1" to="#DispSubMenu.recordcount#">
<td style="border-right: 1px solid #adc0d1;border-top: 1px solid #adc0d1;border-left:1px solid #adc0d1;border-bottom: 1px solid #adc0d1;width:150px;height:30px;" background="images/bg.gif"><a href="#" style="color: #000000" onMouseOver="this.style.color='#93b38e'" onMouseOut="this.style.color='#000000'">
<cfoutput>#SubMenuName#</cfoutput></a>
</td>
    </cfloop>					</div> 
      </cfloop>
	</td>
</tr>

Open in new window

0
Comment
Question by:lulu50
  • 3
  • 2
5 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 35506634
For a query loop use #currentRow# and MOD to do something on record 5, or whatever record you want.

<cfloop query="someQueryName">
     <cfif currentRow mod 5 eq 0>
            it's the 5th record add a break ...<br>
     </cfif>
</cfloop>
0
 

Author Comment

by:lulu50
ID: 35508440
agx_:

It is displaying the whole data on one line

<cfset i="1" />
<cfset ListSubMenuArray = arraynew(2)> 
<cfloop query="DispSubMenu">
<cfset ListSubMenuArray [i][1]="#SubMenuName#" />
<cfset ListSubMenuArray [i][2]="#SubMenuURL#" />
<cfset i= i+1>
</cfloop> 



<cfloop index="i" from="1" to="#arrayLen(ListSubMenuArray )#">
<cfif currentRow mod 5 eq 0>

                             <td style="border-right: 1px solid #adc0d1;border-top: 1px solid #adc0d1;border-left: 
						1px solid #adc0d1;border-bottom: 1px solid #adc0d1;width:150px;height:30px;" background="images/bg.gif"><a href=" ListSubMenuArray[i][2] " style="color: #000000" onMouseOver="this.style.color='#93b38e'" onMouseOut="this.style.color='#000000'"><cfoutput>#ListSubMenuArray[i][1]# </cfoutput></a>
</td><br>
</cfif>
 </cfloop>

Open in new window

0
 
LVL 52

Expert Comment

by:_agx_
ID: 35508923

I think you're confusing code from the other thread with this one.  

It's less complicated than you're thinking. You don't need to create array at all.  Just loop through your query:

<cfoutput query="DispSubMenu">
   ....
       <a href="#SubMenuURL#">#SubMenuName#</a>
  ...
</cfoutput>

As far as the line break it's not clear what you mean. The link is inside a table cell, so do you really want an html line break  ie <br> or a new table row </tr></tr> ... ?
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 35508944
If you really mean an html line break, the #currentRow# code would go *after* the link

<cfoutput query="DispSubMenu">
   ....
   <a href="#SubMenuURL#">#SubMenuName#</a>
  ...
   <cfif currentRow mod 5 eq 0>
         this is the 5th row. do something
   </cfif>
</cfoutput>
0
 

Author Closing Comment

by:lulu50
ID: 35512712
Thank you
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question