home / experts / perl / xhoo / php1 |
|
|
phpHoo, Part IThe Links TableLet's create a table to hold all of our Link data. First, the actual command:
Most of this you should be able to discern for yourself. Every link in the database will have it's own unique identifier (LinkID). Every link will be associated with a Category ID (CatID). Each Link will have a Url, LinkName, and Description using variable length strings. The primary key for this table is the LinkID, and we set the Url to be UNIQUE so that no two entries in the database can contain the same Url. Something to keep in mind when designing your tables. Don't try to think of everything you might need in your data structure at the outset. Your data structures are always going to change while you're programming as you think of things you need in the database. You can come back and modify these tables at any time, and in fact, we're going to be changing the Links table later in this tutorial. Our data structures are completed, so let's give them some data to work with. (Server's responses omitted)
This creates 3 top level categories. Since we did not specify a 'CatParent' for these entries, the CatParent entry was set to NULL automatically. We still need to create some sub-categories under the 'Computers' category but before we do so, we need to know the 'Computers' category ID number:
So 'Computers' is Category ID number 2. We can now assign the CatParent of the sub-categories:
Let's see if everything is still OK:
Let's fill in the rest of the "Computers" sub-categories:
If we want to know what sub-categories are under Computers, we could do this:
To find the names of all the "Top" level categories, we need to write our select statement to handle NULL values. We can't use "where CatParent = NULL" because it's an oxymoron. ("Something" can never equal "Nothing") So we need to use the "IS NULL" construct:
Now that we have some data in the database to work with, let's get down to writing our program to access this data. |
home / experts / perl / xhoo / php1 |
|
Produced by Jonathan
Eisenzopf and
Created: July 20, 1999
Revised: July 20, 1999
URL: http://www.webreference.com/perl/xhoo/php1/