asp menubar question

R

Raphael Gluck

Hi

I am wondering if anyone can help me

I am trying to build a menu bar navigation for my site, and would like the
contents of the menu bar to be linked to a database.
E.G If I have ten initial product Categories, in my main database table, I
want to link it to a menubar to display the main categories on the front
page of my site.

Does anyone know of a script that I could modify?
I've searched quite a bit, for an ASP driven menu bar, and other phrases
too, but I have not found anything yet.

I hope someone can help

Raphael
 
A

Aaron [SQL Server MVP]

There's no magic here... it's just HTML you're creating. So, figure out
what the HTML that you want the menu to look like, and then just build it
from a query. For example, if you wanted it to look like this:

<table>
<tr>
<td><a href=breakdown.asp?cat=1>Category 1</a></td>
<td><a href=breakdown.asp?cat=2>Category 2</a></td>
</tr>
</table>

Then from ASP you would do this:

<%
set conn = CreateObject("ADODB.Connection")
conn.open "<connection string>"
sql = "SELECT CategoryID, Description " & _
"FROM Categories ORDER BY CategoryID"
response.write "<table><tr>"
set rs = conn.execute(sql)
do while not rs.eof
response.write "<td><a href=breakdown.asp?cat="
response.write rs(0) & ">" & rs(1) & "</a></td>"
rs.movenext
loop
response.write "</tr></table>"
rs.close: set rs = nothing: conn.close: set conn = nothing
%>
 
S

Steven Burn

'// Page name: dbfunctions.asp

'// Replace the_database.mdb with the filename of your database
'//
'// Assumes: database is in the same folder as these files
Const objDB = "the_Database.mdb"

Function ConnectToDB(dbPath)
'// The code you use to connect to your database goes here
Set DB = Server.Createobject("ADODB.Connection")
DB.Mode = adModeReadWrite
DB.Open ("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" +
Server.MapPath(dbPath))
Set ConnectToDB = DB
End Function

'// END dbfunctions.asp

'// Page name: menu.asp

<%
Set DB = ConnectToDB(objDB)
Set rst = Server.Createobject("ADODB.Recordset")
rst.Open "Select Menu from tblMenu Order By MENU ASC", db, adOpenStatic,
adLockReadOnly
Do While Not rst.eof
%>
<a href="default.asp?menu=<%=rst("Menu")%>"><%=rst("Menu")%></a><br>
<%
rst.Movenext
Loop
%>

'// END menu.asp

'// Page name: default.asp
<!--#include file="dbfunctions.asp"-->
<!--#include file="menu.asp"-->
<%
strMenu = request.querystring("menu")
Select Case lcase(strMenu)
Case ""
'// Your homepage
Case "home"
'// Do something
Case Else
'// Do something
End Select
%>
'// END default.asp

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
 
R

Raphael Gluck

Thanks you Aaron

I forgot to acknowledge your help, so thanks.

I'll have a try
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top