Yahoo This sample would demonstrate how to quickly build a simple Yahoo! Style navigation bar that displays the paths a use R has taken to a given directory, and also displays a table of "links to" sub-directories of the current director Y.
The the "thing I" beginning any database driven application are to design the data structure. Course, once we into writing the code, many times columns or tables need to is added or modified from the initial D Esign, but has a data framework helps to give us some focus and direction.
Database Layout
I am using a Access2000 database for this example. You can definitely the port this to any RDBMS easily; Just follow the same table architecture.
Let's start by creating a new Access database, and name it Bread.mdb.
Create a single table and name it tblparents.
Open it up into design Mode and add the following columns.
* You can skip building the "from scratch" by downloading the source files.
Bread.mdb
Column Name Data Type
AID Auto Number (Primary Key)
DirName Text
Childdir Text
Parentdir Text
Childdirdescript Memo
Dirdescript Memo
* If Designing for SQL Server, make the AID Column a Identity Field, with a increment of 1 and make sure allow Nulls is Off.
Next we'll want to populate my table with data and so let me explain the logic of the architecture.
Start by inserting the "data for" root of your Web server. This is specified by inserting a forward slash/into the DirName column.
Next Add the directory below the root to the Childdir column (make sure your add the exact directory name as it appears on The server)
Since This is the root directory, leave the Parentdir column blank.
For the Childdirdescript Column, you are want to enter whatever your want the text to read for the link to the Childdir directo Ry that you just entered. (i.e., if you entered music as a childdir Name, your may want the link this points to music to also read music, so you ente R Music in the Childdirdescript column for this entry. If you are want it to read modern Music, enter that)
For the Dirdescript column, enter the text of your want to appear to describe the current directory, and the which in the Root folder. I used the word home as the description so users would always know that clicking on this link would bring me back to th E beginning.
Repeat this process for each sub directory you have below your Web root.
Note:make sure to create the actual directory structure on the Web server if it does is not already exist.
Your data should look similar to this:
After your complete this process make sure your also make entries to the database for the directories just. In me case I added a directory music, so now I must add the appropriate Fields for music. Since Music has a parent directory (Root), we must specify it by adding a forward to slash for Parentdir.
Populate the data for Music and any of the other Sub directories.
Refer to the screenshot below for my example.
* The Childdir columns should contain all directories below the Root.
The Code
Now so we have some valid data, let's start by creating a couple of functions. We'll house this functions in a include file, named Folderfunctions.asp. The the ' the ' the ' the ' want is ' a function to ' return ' the current physical directory of the Web server. We'll use this function while we do a database lookup to build the appropriate links and path history. I named this function Getthispath.
The ' thing our ' function needs to ' do ' get ' current full path ' from the server. We'll use the Path_info method of the "ServerVariables collection to look at it up."
Since we want the current directory name, we'll split the string returned from Path_info at the forward slash, whic H'll create an array containing all the directories above the current directory. Then we'll need to loop thru the entire array to pull only the data we need (the current directory). We'll accomplish this by setting We are loop to exit on the next to the last entry in the array (the very last entry would Be the page name and we don t want that). The way we are to tell the loop to execute as many times as values the array holds minus one. We are information by asking the "array for it" upper Bounds.
Then we'll set the "functions return value" to "last entry" in our loop by overwriting the "return value in" Each loop, WH Ich would be is the current directory. However, if the the array is empty, it means we are at the root of the server and we need to set the return value