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'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.
 
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.
 
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:
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>"
 
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.
 
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?
 
Mr^B said:
Rs(0)
Rs(1)

etc...and see if that helps.

Sorry, not sure what you mean by that ... could you explain further?

I'm only learning ASP and using MS Access due to using it in work and wanting to know all the in's and out's of it .. once I've learnt it properly I'll move onto something more advanced.

I'm going to get a book on this soon, just trying to start understanding the basics at the moment like connecting to a database, unfortunatly with not nothing much in the way of microshafts way of doing things then I'm not getting very far at the moment :-/

Thanks for all the help so far though
 
Mr^B said:
If that's all a bit like doublt-dutch, if you can show us the structure of the table, we can tell you what's going wrong.

I can understand it ok, but for future reference I'd rather just use the actual column names.

My database is as follows:

PageID | PageTitle | PageFile
1 | Home | home.asp
2 | Pictures | pictures.asp
3 | Floorplan | floorplan.asp

etc...

I've just released though that I don't want the pages in different files, I want one the one div to determine which page the user is at then put the relevant data into each <p></p> or <img></img> tag. Still, for now I'd like to get a database linked up.

Edit: Just tried putting in 2 and 1 and its working fine :), I'm going to give it a rest now though until the book i've ordered arrives

Thanks for all the help everyone,

Steven
 
Last edited:
Back
Top Bottom