It depends on what you're trying to accomplish.
The LoopCounter is useful in situations where you want to count; i.e. from 1 to 10 to create 10 items.
The Repeat Region is useful to repeat an item for each record in a recordset. In your case, the repeat region seems to make the most sense. It doesn't really matter where you use the code; the Recordset is defined before any HTML, so you can use it anywhere in your page. The problem with the Repeat Region is that it is a bit picky. It's difficult to repeat ASP code that writes out JavaScript in the <head> section of the page. It also adds too much <% and %> (though completely legal and correct), so you end up with slow code, so it's better to write some code yourself.
Anyway, your code below looks good; it will write out a list of links. To combine it with the menu code, try something like this:
Code:
<%
Dim rsProducts
Dim rsProducts_numRows
Set rsProducts = Server.CreateObject("ADODB.Recordset")
rsProducts.ActiveConnection = MM_connTestSite_STRING
rsProducts.Source = "SELECT Category, ID, Name, URL FROM Products ORDER BY Category ASC, Name ASC"
rsProducts.CursorType = 0
rsProducts.CursorLocation = 2
rsProducts.LockType = 1
rsProducts.Open()
rsProducts_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
rsProducts_numRows = rsProducts_numRows + Repeat1__numRows
%>
// Other HTML stuff here....
function mmLoadMenus() {
if (window.mm_menu_1120161301_0) return;
window.mm_menu_1120161301_0 = new Menu("root",300,18,"",12,
"#000000","#FFFFFF","#CCCCCC","#000084",
"left","middle",3,0,1000,-5,7,true,true,true,0,true,true);
<%
While ((Repeat1__numRows <> 0) AND (NOT rsProducts.EOF))
Response.Write("mm_menu_1120161301_0.addMenuItem(""" & _
Replace(rsProducts("Name"), " ", " ") & _
""",""location='Item.asp?ID=" & rsProducts("ID") & "'"");")
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsProducts.MoveNext()
Wend
%>
mm_menu_1120161301_0.hideOnMouseOut=true;
mm_menu_1120161301_0.bgColor='#555555';
mm_menu_1120161301_0.menuBorder=1;
mm_menu_1120161301_0.menuLiteBgColor='#FFFFFF';
mm_menu_1120161301_0.menuBorderBgColor='#777777';
mm_menu_1120161301_0.writeMenus();
} // mmLoadMenus()
Before you can run this page, you have to add a recordset called rsProducts to the page. This recordset needs at least a Name and a ID column, or you should modify the code accordingly.
Basically, this code loops through the recordset and writes out a menu item for each item in the recordset.
I have a column called Category in my recordset. If you want, you can loop through this code and write out a Main menu item for each new category. Then each product that belongs to that category gets its own sub menu item. I'll leave that to tomorrow's exercise ;)
The code also uses the Replace method to repalce spaces with their non-breaking space counterpart. If you don't do this, you'll end up with menu text over a couple of lines, instead of on one line.
Hope this helps and if not, please let me know.
Regards,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.