what i am trying to do is make it so that instead of having an actual physical file for each and every Teacher's webpage it just uses variables like this: http://website.com/default.asp?id=123456 and uses just one template.
Does that clear it up a bit?
[web] ASP Question!
I think it's best to find yourself some ASP tutorials. It's a fairly 'old' scripting language, so there should be tons of learning material online.
Besides if you already familiar with PHP scripting, learning some basic ASP shouldn't be a problem. The syntax (VB) is different, and you have actually less functions to work with, but the idea is the same.
Anyway, to get you started:
Note that I haven't tested it, and that it's an extremely simple example.
The code above will parse the id parameter from the querystring and store it in a variable id. How to then use this id is up to you. In my sample I have included two options: one is using a database to select the content to be displayed, the second is using a switch statement and some hard-coded text (notice the constant to switch between these two).
Besides if you already familiar with PHP scripting, learning some basic ASP shouldn't be a problem. The syntax (VB) is different, and you have actually less functions to work with, but the idea is the same.
Anyway, to get you started:
<%Option Explicit ' not necessary, but good practiceDim id' get id parameter, in this case we're checking if it's a numberIf IsNumeric(Request("id")) Then id = CLng(Request("id"))Else id = 0 End If%><html><body><%Const USE_DATABASE = FalseIf USE_DATABASE Then ' using a database Dim conn Dim rs ' initialize connection and recordset Set conn = Server.CreateObject("ADODB.Connection") Set rs = Server.CreateObject("ADODB.Recordset") conn.Open("your connection string here") rs.Open "SELECT TOP 1 title FROM Table WHERE id = " & id, conn ' if result set contains a record, print it If Not rs.EOF Then Response.Write("<h1>" & rs("title") & "</h1>") End If rs.Close()Else ' show content based on id (hard-coded) Select Case id Case 1: Response.Write("<h1>This is page one</h1>") Case 2: Response.Write("<h1>This is page two</h1>") Case 3: Response.Write("<h1>This is page three</h1>") Case Else Response.Write("<h1>This is the default page</h1>") End SelectEnd If%><a href="default.asp">default page</a> | <a href="default.asp?id=1">page one</a> | <a href="default.asp?id=2">page two</a> | <a href="default.asp?id=3">page three</a></body></html>
Note that I haven't tested it, and that it's an extremely simple example.
The code above will parse the id parameter from the querystring and store it in a variable id. How to then use this id is up to you. In my sample I have included two options: one is using a database to select the content to be displayed, the second is using a switch statement and some hard-coded text (notice the constant to switch between these two).
YAY!! So far I have gotten it to work!
I was wondering how would you call a variable that has already been extracted from a database like in PHP: <? $variable ?> So that you can call it several times outside the php. And how would I change the page title according to the teachers name.
I was wondering how would you call a variable that has already been extracted from a database like in PHP: <? $variable ?> So that you can call it several times outside the php. And how would I change the page title according to the teachers name.
No offense, but I am not going to write all your code. I gave you an example to get you going, but it still requires some effort from you. Like I and others already pointed out, find a book or go through some online tutorials to get a better understanding of ASP.
I'll be a nice guy and answer your last two post: [smile]
You mean who to write to the reponse stream?
Take a look at this section of the code. It checks if a record has been found. This is where you can handle your not-found case.
I'll be a nice guy and answer your last two post: [smile]
Quote:Original post by blackbirdblackbird1
I was wondering how would you call a variable that has already been extracted from a database like in PHP: <? $variable ?> So that you can call it several times outside the php. And how would I change the page title according to the teachers name.
You mean who to write to the reponse stream?
<%= myVariable %>
Quote:Original post by blackbirdblackbird1
How would you have it display a message if the ID is not found in the database?
Take a look at this section of the code. It checks if a record has been found. This is where you can handle your not-found case.
' if result set contains a record, print it If Not rs.EOF Then Response.Write("<h1>" & rs("title") & "</h1>") End If ' if result set contains a record, print it (NEW VERSION) If Not rs.EOF Then Response.Write("<h1>" & rs("title") & "</h1>") Else Response.Write("<h1>Entry not found</h1>") End If
When I add the "Entry not Found" message I get this:
I only get this error when there is no entry with that ID.
Thanx so much for all your help!
Error Type:ADODB.Field (0x80020009)Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record./faculty/history.asp
I only get this error when there is no entry with that ID.
Dim conn Dim rs ' initialize connection and recordset Set conn = Server.CreateObject("ADODB.Connection") Set rs = Server.CreateObject("ADODB.Recordset") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open("c:/inetpub/ahsftp/AHS/design/faculty/teacher.mdb") rs.Open "SELECT TOP 1 name, photo, quote, p_1, p_2, p_3, p_4, p_5, p_6, p_7, subject, room, office_hours, voice_mail, email, fav_sports, fav_subj, fav_food, fav_movie, fav_music FROM history WHERE id = " & id, conn ' if result set contains a record, print it (NEW VERSION) If Not rs.EOF Then Response.Write("<h1>" & rs("name") & "</h1>") Else Response.Write("<h1>Either the Teachers info has not been added yet or you have been given an invalid teacher ID.</h1>") End If%>
Thanx so much for all your help!
I, like most others here, don't know crap about ASP, but aren't you able to 'select' your programming language, something like: "<script language='x' runat='server'>"? If you like your C-style syntax, you can try using C#, but that doesn't have anything much to do with the question at hand (though, from the ASP code I've seen so far, the methods you have to take to get to that information looks like crap to me).
Or is that ASP.NET-specific?
Or is that ASP.NET-specific?
Quote:Original post by deadimp
I, like most others here, don't know crap about ASP, but aren't you able to 'select' your programming language, something like: "<script language='x' runat='server'>"? If you like your C-style syntax, you can try using C#, but that doesn't have anything much to do with the question at hand (though, from the ASP code I've seen so far, the methods you have to take to get to that information looks like crap to me).
Or is that ASP.NET-specific?
ASP != ASP.NET, ASP is VBScript only.
Quote:Original post by WanMasterQuote:Original post by deadimp
I, like most others here, don't know crap about ASP, but aren't you able to 'select' your programming language, something like: "<script language='x' runat='server'>"? If you like your C-style syntax, you can try using C#, but that doesn't have anything much to do with the question at hand (though, from the ASP code I've seen so far, the methods you have to take to get to that information looks like crap to me).
Or is that ASP.NET-specific?
ASP != ASP.NET, ASP is VBScript only.
well, JScript can be used, but it is so poorly documented and supported that it might as well not be available.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement