ASP page navigation through Access database?

Associate
Joined
12 Aug 2004
Posts
1,009
Location
Glasgow, Scotland
Hi :)

I'm just starting to convert one of my websites from PHP to ASP (to learn it properly for work). Most things seem fairly easy to do but I'll no doubt have a good few questions to ask along the way if thats alright :)

It just so happens I have arrived at my first hiccup already. I'm trying to make it a completey database driven website so the client can add, edit and delete any page on the website whilst monitoring traffic etc. etc. through a secure login area. So I can have each page generated from a table within the database I was wondering just how I would go about doing this?

Basically what I'm trying to figure out is how to I can create a MS Access database with all the pages in it and what file each is linked to, save that database to my server then from the index file link to the database so it shows all the pages by bringing them up as links. When a user clicks on one of these links they are shown the associated page file through a div made further down in the index file.

I've got some books on ASP but they seem to have overlooked this and gone straight into add and deleting records from databases. Can anyone point me in the right direction of a good tutorial on how to do this or maybe explain in detail how to?

Thanks :)

Steven
 
Anyone?

Everything else I can probably figure out for myself but with this initial step I'm stuck :confused:

As said before I'd like to create a database of all the pages, which all will be included in the horizontal menu. All I'm wanting to know is how to link up the MS Access database to the ASP file and tell it to display all pages across the menu.
 
I am not sure where you are trying to go with this? Are you saying to want to create the Database through ASP or just add a table for each page?

TrUz
 
I'm trying to figure out, and get some to explain (or link to a tutorial) on how to create a database with Microsoft Access with a table consisting of 3 fields - the id, page name and the page filename.

So for example if I had a table like so...

pages
-------------------------------
1 | Home | home.asp
2 | About Us | aboutus.asp
3 | Contact Us | contactus.asp

...and I two seperate div's within my index.asp file, one div containing the menu and the other displaying each pages content.

I'd like to link this database and table to both div's so that all the different pages get listed in the menu div linking to their seperate files so they'll load up in the content div. The reason I want this is so I can link to the database in a secure login area and have the ability to add, edit or delete the pages.
 
I am not sure how you create a Database on the fly but to create a Table you do this:
Code:
CREATE TABLE pages (page_id Long, page_title TEXT, page_name TEXT);
Hope this helps.

TrUz
 
hmm, i don't think that ties in with creating the database and table within Microsoft Access but thanks anyway, i appreciate the help... at least I've got my point across better now :)

...hopefully someone else with a bit more knowledge and experience on the subject could help?

Thanks :)
 
Oh so you are actually using Access to create the Database and Tables? I though you was trying to do it VIA code!

To create a Database just open Access and select Blank Access Database.

To create the Table click on Tables then select Create table in design view.

TrUz
 
how to create a table in acess

thats how you create your table

then you need to from yuour asp page scan through your db and assign the recordset values to a hyperlink

i think/hope this is what your after, my asp is a bit rusty

<%
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.Recordset")
Conn.Open ("YourDBConnection")
SQL = "SELECT * from DBNAME"
Set Rs = Conn.Execute(SQL)
%>


<div id=divnumber2>
<%
Do While Not Rs.eof
Response.Write "<a href=" & Rs("PageName") & ">" & Rs("PageTitle") &"</a>"
Loop
%>
</div>
<%
Rs.Close
Set Rs = Nothing
Conn.Close
Set Conn = Nothing
%>

just add your connection string .





MagSafe said:
hmm, i don't think that ties in with creating the database and table within Microsoft Access but thanks anyway, i appreciate the help... at least I've got my point across better now :)

...hopefully someone else with a bit more knowledge and experience on the subject could help?

Thanks :)
 
Hmm, that looks good Hugo...

Could you go into a bit more detail on the variables used, and how I would go about associating them with the table (e.g PageName & PageTitle ... are these field names or something?) ... and with DBNAME, would I just replace that with say, for example /databases/pages.mdb

Also, assuming divnumber2 is the menu area, how would I like the PageName to display into divnumber1?

Thanks,

Steven.
 
PageName and PageTitle are just database column names u would replace them with whatever you name yours when you create your table.

the way your connection is opened depends on your hosting and its setup your example looks good to me.


MagSafe said:
Hmm, that looks good Hugo...

Could you go into a bit more detail on the variables used, and how I would go about associating them with the table (e.g PageName & PageTitle ... are these field names or something?) ... and with DBNAME, would I just replace that with say, for example /databases/pages.mdb

Also, assuming divnumber2 is the menu area, how would I like the PageName to display into divnumber1?

Thanks,

Steven.
 
Thanks Hugo :)

Almost there, I just need to figure out how to figure this part out properly...

Also, assuming divnumber2 is the menu area, how would I link the PageName to display into divnumber1?

Would I not include it within the href link by saying "index.asp?page=home" or something similar ... if so how would I go about doing that with ASP and the database talked above?

...or is that what you mean by it being determined by how my host is setup?
 
Last edited:
you could do it your that way by doing it something like this

<%
if Request("Page") = "" then
else
page2load = Request("page") & ".asp"
%>

then in your second div use

<%

server.execute(page2load)

%>

this would effectively load the page into whatever div you want.

your link would look like this

Response.Write "<a href=index.asp?Page=" & Rs("PageName") & ">" & Rs("PageTitle") &"</a>"

MagSafe said:
Thanks Hugo :)

Almost there, I just need to figure out how to figure this part out properly...



Would I not include it within the href link by saying "index.asp?page=home" or something similar ... if so how would I go about doing that with ASP and the database talked above?

...or is that what you mean by it being determined by how my host is setup?
 
Last edited:
Thanks for that ... just wondering if the "Page"/"page" your refering to refers to the database? ... as I'd need that to automatically tell what pages where in the database so if I added a new one it would automatically created a href link within the menu to it (and then display then new page in content div)

HTMLHugo said:
you could do it your that way by doing it something like this

<%
if Request("Page") = "" then
else
page2load = Request("page") & ".asp"
%>

then in your second div use

<%

server.execute(page2load)

%>

this would effectively load the page into whatever div you want.

your link would look like this

Response.Write "<a href=index.asp?Page=" & Rs("PageName") & ">" & Rs("PageTitle") &"</a>"
 
this code is for loading the page into the div you want,the top code will scan through the database and create the links

MagSafe said:
Thanks for that ... just wondering if the "Page"/"page" your refering to refers to the database? ... as I'd need that to automatically tell what pages where in the database so if I added a new one it would automatically created a href link within the menu to it (and then display then new page in content div)
 
HTMLHugo said:
this code is for loading the page into the div you want,the top code will scan through the database and create the links

ah right .... i get you now :)

thanks for all the help mate, i'll have a go over the weekend sometime and hopefully get it working
 
Hi again,

I've been mucking about with it for a bit and ran into an error...

Error Type:
ADODB.Recordset (0x800A0CC1)
Item cannot be found in the collection corresponding to the requested name or ordinal.
/thepines/index.asp, line 37

which seems to be this line...

Do While Not Rs.eof

I'm pretty sure it can see the database fine as it brought up another error when I put in a wrong field name and it corrected itself when I changed it.

I've included the code for my index file below...

Code:
<%
	Set Conn = Server.CreateObject("ADODB.Connection")
	Set Conn = Server.CreateObject("ADODB.Connection")
	Conn.Open ("thepines")
	SQL = "SELECT * from pages ORDER BY PageID"
	Set Rs = Conn.Execute(SQL)
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

	<head>
		<title>The Pines</title>
		<meta name="description" content="The Pines is a lovely villa located in florida , it is a 15 minute drive to all the main theme parks (e.g Disney World , Sea World etc) , Our villa looks onto a wonderful forrest and fits luxury standards throughout" />
		<meta name="keywords" content="orlando,orlando florida,florida,florida villa,orlando villa,calabay parc,calabay,parc,calabay parc villa,the pines,the pines villa,pines villa,pines,villa,villa 15 minutes from disney,villa near disney world,villa near disney,villa near sea world" />

		<link type="text/css" rel="stylesheet" href="styles.css">

		<script type="text/javaScript">
			function popUp(URL)
			{
				day = new Date();
				id = day.getTime();
				eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=450');");
			}
		</script>
	</head>

	<body>

		<div id="container">
			<div id=top><img src="images/logo.jpg" alt="The Pines" width="705" height="169" /></div>
			<div id="menu">
				<div id=divnumber2>
					<%
						Do While Not Rs.eof
						Response.Write "<a href=" & Rs("PageFile") & ">" & Rs("PageTitle") &"</a>"
						Loop
					%>
				</div>

			</div>
			<div id="main"><br /><img src = "images/background.jpg" alt="Background Image" width="167" height="137" /></div>
		</div>
	</body>

</html>

<%
	Rs.Close
	Set Rs = Nothing
	Conn.Close
	Set Conn = Nothing
%>

Thanks for the help :),

Steven.
 
You need to have an

Rs.MoveNext

command before the Loop.

It's not like PHP in that respect, you have to tell it to move onto the next record.
 
Mr^B said:
You need to have an

Rs.MoveNext

command before the Loop.

It's not like PHP in that respect, you have to tell it to move onto the next record.

I tried that, but it still doesn't work ... I would've thought that it would still work any except only allowing one record to come through instead of all of them.

Any other ideas?
 
Back
Top Bottom