Database Articles
  Home arrow Database Articles arrow Page 2 - Adding a Poll to Your Web Site
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE ARTICLES

Adding a Poll to Your Web Site
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 125
    2005-06-29

    Table of Contents:
  • Adding a Poll to Your Web Site
  • Setting the Stage
  • Creating the Form
  • The Complete showvotes.php
  • Expanding the Poll
  • Polling Accuracy

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Adding a Poll to Your Web Site - Setting the Stage


    (Page 2 of 6 )

    Let's suppose that Nashville's less known but more pretentious music hall, the Grand Old Opera, has decided to add a poll to their website to measure their visitors' preferences.

    The first step is to create the database. For now we will create one table, the poll answers. Later I'll discuss ways to expand the database to handle a multi-question survey or a series of polls.

    The following code will create the database and table, insert the choices, and grant permissions for the user.

    CREATE DATABASE polls;
    USE polls;
    CREATE TABLE poll_answers
      (choice INT NOT NULL PRIMARY KEY,
      activity VARCHAR(35) NOT NULL, votes INT DEFAULT 0);
    INSERT INTO poll_answers(choice, activity, votes) VALUES(1, "Going to the opera", 4), 
      (2, "Listening to opera music on CD", 2),
      (3, "Getting bitten by a ferret", 14);
    GRANT SELECT, UPDATE ON polls.* TO user IDENTIFIED BY 'pass';

    This creates a database named polls, and a table named poll_answers. This table has three fields: choice, a number representing the choice; activity, a text description of the choice; and votes, the number of votes this choice has received. Later I'll explain how to expand the database to handle multiple polls.

    Normally we would initialize the votes field to zero for each choice, but for this tutorial I am using nonzero values to simulate a history of previous votes.

    The GRANT statement lets the user with name 'user' and password 'pass' select and/or update rows from the database. In a live environment, you'll want to choose a username and password that would not be so easy for a malicious user to guess.

    More Database Articles Articles
    More By Codewalkers


       · I've written a poll system myself and the method I use for accuracy is through...
       · I think the key word there is community. If you've already got an interactive web...
       · with the number of poll scripts already available for free on scripts site, it would...
       · Everything seems to work nicely, but the graph doesn't show at all. The vote totals...
       · Hey LadieS!
       · Great tutorial.. and I couldn't agree less with the guy who said that it'd be better...
       · Excellent tutorial. Never looked at setting up a poll for my site, but might well...
       · I personally would have thought that using the width attribute of an img tag (src...
       · Where is the content in pdf?Why is the file half done?
       · what is ferret?
       · HiOnline poll is great way . But only concern i have with Poll result. Suppose we...
     

    DATABASE ARTICLES ARTICLES

    - More on Query Optimization for Oracle Databa...
    - Query Optimization in Oracle
    - Clusters and Other Data Structures for Oracle
    - Using Indexes with an Oracle Database
    - The Basics of Data Structures in Oracle
    - Oracle Data Structures
    - Best Practices for PL/SQL Variables
    - What`s Code Without Variables?
    - Clauses, Sorting, and SQL Queries
    - The From Clause and SQL Queries
    - Query Primer
    - Full Text Searches and Strings
    - Searching with Strings
    - Pattern Matching with Strings
    - Working with Cases of Strings





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT