To read the article online, visit http://www.4GuysFromRolla.com/webtech/071099-1.shtml

Creating User Polls


It seems like every site has a poll on their start page these days, especially the big media sites, such as ABCNEWS.com and MSNBC.com, just to name a couple. Well, I've got news for you: it's time to conform. So, let's look at how we can add professional looking user polls to our ASP websites.

We'll need two tables in a database to accomplish this. The first table is called Poll, and contains information on all of our Polls. The really isn't much information that it needs to store, just the Poll question and the run dates for the poll. Let's look at the structure for this table:

Poll
PollIDAutonumber
PollQuestionText (150)
DateStartDate/Time
DateEndDate/Time

DateStart and DateEnd are used to determine the running times of your polls. This way, you can create many polls, with some scheduled for the future. Also, you can bring back old polls, or easily show the results of older polls.

The second table will hold the questions for each of our polls, and will aptly be named PollOption:

PollOption
PollOptionIDAutonumber
PollIDNumber
QuestionTextText (100)
VotesNumber

PollOption.PollID is a Foreign Key to Poll.PollID. It represents what poll this question belongs to. So, let's say we want to have a poll that asks, "Have you programmed Cold Fusion webpages before?" and runs from 7/13/99 to 7/20/99. We want to give the users two options to select, "Yes" and "No." Here's the steps we'd need to do:

    1.) Insert a row into Poll, setting PollQuestion to "Have you programmed Cold Fusion webpages before?", DateStart to 7/13/99 and DateEnd to 7/20/99.
    2.) Insert two rows into PollOption. Both rows would have Votes initially set to zero and PollOption.PollID set to the the Poll.PollID that was assigned in Step 1. For the first row, set QuestionText to Yes, and for the second row, set QuestionText to No.

That's it! It's that easy! Now, all we need to do is add some ASP code to the page that we want to display the poll/poll results. If you haven't already seen ABCNEWS.com's poll, I'd suggest checking it out; it has the UI I'm going after with my approach.

Once you're ready, let's move onto Step 2, where we'll look at the ASP code needed to make our polling system a reality!

  • Proceed to Step 2


  • Article Information
    Article Title: Creating User Polls
    Article Author: Scott Mitchell
    Published Date: Saturday, July 10, 1999
    Article URL: http://www.4GuysFromRolla.com/webtech/071099-1.shtml


    Copyright 2017 QuinStreet Inc. All Rights Reserved.
    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers