Rick Curtis - Tutorial 6

Including Text Files Dynamically
Part 2 - Dynamic Navigation

In Tutorial 5 I showed you how to dynamically merge text files into your pages. Now we are going to pump it up again. My article database references some short articles (one page) and some long ones (20 pages). Well, we don't want people to have to load the entire article so we break up the text file into pieces. Let's look at the database design again.

The Article Database

Now you'll notice that I reference the original text file to be included in the ArticleURL field and subsequent text files as Page2URL, etc.

Field Name Datatype Description
ArticleID Autonumber Primary key
Title varchar(75) Article Title
ShortDesc varchar(255) Short description
ArticleURL varchar(50) The file name of the first page of the article
Page2URL varchar(50) The file name of the second page of the article (if the article is long enough to be split)
Page3URL varchar(50) The file name of the second page of the article (if the article is long enough to be split)
Page4URL varchar(50) The file name of the second page of the article (if the article is long enough to be split)

Sample Data

Field Name Sample
ArticleID 100
Title Article Title
ShortDesc Short description of the article
ArticleURL 100.asp
Page2URL 100-2.asp
Page3URL 100-3.asp
Page4URL 100-3.asp

The Web Site

We need to make a few changes in the code from Tutorial 5.

The first thing to do is to put a recordset on the page that shows the articles and authors. Below all of the UltraDev recordset code and just above the <html> tag add the following code: This script has to come after the UltraDev 'Go to Specific Record' code so that the correct ArticleURL is pulled up.

<%
Dim ArticleLink, ArticleFile
If Request.Form("ArticleLink") = "" then
  ArticleLink = rsArticleID.Fields.Item("ArticleURL").Value
  Else ArticleLink = Request.Form("ArticleLink")
End If
ArticleFile = Chr(34) & ArticleLink & Chr(34)
%>

The rest of the code is that same as in Tutorial 5. Now we are going to add some Navigation buttons at the botton of the page. This will let people move from one page to another. It will look something like this.

New Search

 

Within each table cell each submit button is tied to it's own form. So there are 4 forms on the page. Each form has two hidden fields--ArticleID and ArticleLink. So here we see the code for the Page 1 button and the Page 2 Button. The Page 3 and 4 buttons are the same as the Page 2 button except using Page3URL or Page4URL as the recordset values.

<form name="form4" method="post" action="ArticleInc.asp">
<input type=hidden name="ArticleID" value="<%=(rsArticleID.Fields.Item("ArticleID").Value)%>">
<input type=hidden name="ArticleLink" value="<%=(rsArticleID.Fields.Item("ArticleURL").Value)%>">
<input type="submit" name="Submit" value="Page 1">
</form>

<%
'This code evaluates if Page2URL is NOT NULL, if so it shows the next page link
If ((rsArticlesAuthors.Fields.Item("Page2URL").Value)<> "" ) Then %>

<form name="form4" method="post" action="ArticleInc.asp">
<input type=hidden name="ArticleID" value="<%=(rsArticleID.Fields.Item("ArticleID").Value)%>">
<input type=hidden name="ArticleLink" value="<%=(rsArticleID.Fields.Item("Page2URL").Value)%>">
<input type="submit" name="Submit" value="Page 2">
</form>
<%End If%>

Okay so what's happening here? The user does a search and ends up on an Article List Page that sows just Title, Author, and Date. Clicking the ArticleName uses the Go to Detail Page which brings her to ArticleInc.asp. The ArticleID is passed to a Stored Procedure that calls up only that Article. The first piece of code I showed you looks to see if there is a Request value that has been passed with an ArticleLink. This doesn't happen when page one initially loads so it defaults to using the recordset value for Page 1 (ArticleURL). When the user clicks the Page 2 button (if there is a Page 2) the form is resubmitted to itself using the ArticleID and the ArticleLink values from the hidden form elements. This reloads the recordset still keeping the same ArticleID but using a new value for the text file to be incldued. The nice thing is that the rest of the page (title, author, etc.) from the recordset is also relaoded. This is preferable to simply calling a page with a new included text file but which is missing that opening section.

Since every article will always have a Page 1 that button will always appear at the botton of the page. For each subsequent button the IF..THEN statement evaluates if the NextPageURL has a value. If so it creates the button, if not it doesn't. SO we have created the ability to break up our article files into smaller chunks, dynamically include them, and create a dynamic navigation system for moving through a multi-page article. There may be other cleaner ways to code this. If you come up with one, please let me know. rcurtis@princeton.edu

I hope this is helpful to people. Happy coding.

Rick Curtis

Copyright © 2000 All rights reserved Rick Curtis, Princeton, NJ, USA
Macromedia and UltraDev are trademarks of the Macromedia Corporation.