<%@LANGUAGE = "VBSCRIPT"%> ASP example


This file is a simple example of how to get items from a access database. It's more or less the same as the javascript example, only coded in VBSCRIPT. I will make a more advanced example later. The table consist of 4 simple columns:

menuID - Autonumber - the id of the menuitem.
mName - String - The menu name
mLink - String - The link
parent - Number - a recursive relation to menuID.


This can rather easily be converted to control the entire menu and by adding a server-side admin *anyone* could easily change the menu. The new menumaker that I will hopefully soon have time to make will probably use something like this.

On this site I use a similar approuch, the only difference is that I make a js file everytime I update, that way I don't have to get the items from the database on every visit. I will try and make an example like that as well later.

ASP source-code:
'*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'ASP CODE START - READING ITEMS FROM THE DATABASE
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Sub readItemsFromDatabase
  'The path to your database:
  Dim db,q,rs,rsarr,menuID,mName,mLink,parent,cols,max
	
	db ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("menu.mdb")
  
  q = "SELECT menuID,mName,mLink,parent from tblMenu ORDER BY parent,menuID ASC"
  
  Set rs=Server.CreateObject("ADODB.Recordset")
  rs.CacheSize = 25 		' Cache data fetching
  rs.CursorType = 3
  rs.LockType = 3
  
  'Opening database --- --
  rs.Open q,db
  
  'Now using getRows because that's so sexy :}
  if NOT rs.EOF then
    rsarr = rs.GetRows()
		max = Ubound(rsarr,2)
  else 
		max = 0
  end if
  'Closing database, we don't need it anymore - we have the info in the array
  rs.close()
  Set rs = Nothing
  
	row=0
	do while(row<=max) 'Looping rows
    'Setting variables 
    menuID = "m" & rsarr(0,row)
    mName = rsarr(1,row)
    mLink = rsarr(2,row)
    if(mLink="null") then mLink="" 
    parent = rsarr(3,row)
    if(parent<>0) then
			parent = "m" & parent
    else 
			parent=""
    end if
		'Making menu item
    Response.write("oCMenu.makeMenu('" & menuID & "','" &parent & "','" & mName & "','" & mLink & "')" & vbcrlf)
  	row = row + 1
	loop
End Sub

'Calling sub
call readItemsFromDatabase

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'ASP CODE END - READING ITEMS FROM THE DATABASE
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%