Where to Start - Page 2
January 8, 2001
The first thing to do is figure out where to start. For our
purposes in this article, which is to learn about coding in a
practical context, let's just assume that you have a page design
complete and you want your poll to be in a simple HTML
table.
With that in mind, I am going to try to ignore HTML as much as
possible so we can focus primarily on the guts of the system -
the ASP code.
The next step is to design a database for your polls. I am going
to use Access 2000
to accomplish this task. The database is called polldb.mdb and
it has two tables: tbl_questions and tbl_responses. These tables
are related with a one-to-many relationship where tbl_responses
contains the foreign key reference to the primary key of the
tbl_questions table. Just to be certain everyone is on the same
page, here is a translation of what I just said.
The tbl_responses table contains responses for the various poll
questions. Each poll question can have zero or many responses.
That means for each record in tbl_questions there will be zero or
many corresponding records in the tbl_responses table. To make
this possible, the two tables must be related - which means
exactly what it sounds like it means. Practically speaking,
there must be a column in the tbl_responses table that stores the
value of the primary key (technically a candidate key but let's
not go there) of the tbl_questions that the responses belong to.
See below for an illustrated explanation.
|
Now, in order to save a little time, I have setup both tables
myself and am providing a screenshot of their design in the
screenshot below:
|
Finalizing the Database
Once you have your database designed, you need to populate the
tables with an initial question and options so you can later see
the fruits of you labor. Come up with a generic question for the
first record in the tbl_questions table and then add a few
options in the tbl_responses table (make sure for each option you
store the PollID of the tbl_questions in the PollID field of the
tbl_responses table - otherwise you will not have a relationship
between the two and nothing will work later on).
Once you are satisfied with your first question and its options,
the next step is to make your database Web-ready. For us, that
means registering a DSN for the database with the operating
system (we are, or course, assuming Windows 9x, ME or NT/2000).
If you do not know how to do this, I explained how, step-by-step,
in another article,
so take a timeout from this article and
check it out.
When you are ready to actually set up your DSN entry for this
example system, call it polldb (you can name it anything you
like, just be advised that I will refer to it as polldb
throughout all the code examples).
Poll Your Visitors with ASP
Poll Your Visitors with ASP
The Birth of a Poll - Page 3
|