KidsLovePC Contact Us
  Home   PHP  Graphics ASP  JavaScript   J2EE  HTML  JAVA   Swing   Webtip  Forums  Lyric  Free sheet music  Ringtones

A Poll/Rating system in PHP and MySQL

Before you start this lesson, please read the following lessons for your reference:

This lesson will show you how to create a simple poll/rating system in PHP and MySQL. The could be used for any number of items you want to rate without changing a bit.

You may use it to do opinion poll, rate your software,images, news, music,anything.

Here is the example:

Vote for this tutorial
Warning: mysql_connect(): Access denied for user 'chinesel_hsun'@'localhost' (using password: YES) in /home1/chinesel/public_html/kidslovepc/php-tutorial/pollresult.php on line 15
Unable to specified database

This tutorial includes 3 sections:

  1. Create database : how to save polling/rating results in MySQL
  2. Dealing poll/rate Form: how to saving polling/rating result to database and how to set cookie to prevent client repeat voting on the same item.
  3. Retrieve poll/rate result: retrieve poll/rate result for item and assign corresponding poll/rate icon to it.

Poll database in MySQL

We need a database to save polling/rating result, such as item id (which software is rated), how many times rated and the average rating/polling result.

The following is the SQL query for creating a polling table in MySQL.

CREATE TABLE `polling` (
`itemid` INT NOT NULL ,
`votes` INT NOT NULL ,
`result` DECIMAL( 2, 1 ) NOT NULL ,
PRIMARY KEY ( `itemid` )

Using phpMyAdmin Create Database could show you how to use PhpMyAdmin to create above table. Note that for result column, which has type DECIMAL(2,1), you need put 2,1 in "Length/Values*" field, shown in the following image:

polling/rating, php mysql

Decimal(2,1) means result column has 2 digits in total, one digit after digit point. Since we only want rate our items like: no rating(0),bad(1),fair(2), good(3),very good(4) and excellent(5), the average result will be between 0.0 and 5.0,like 3.2, 4.5, etc. If you want more precise result, you may use more digits in decimal type, for example Decimal(7,4).

In this lesson, we make rating on one item for demo purpose. Before we do the polling/rating, the rated item should exist in database.

You may use PhpMYAdmin input the following record to your polling table:

itemid : 1, votes: 0, result: 0.

In PHHMYAdmin panel, click on Insert tab and input data like the following image:

polling/rating, php mysql



Next: dealing with poll/rate form
PHP Calendar
Comprehensive PHP Web Calendar
Configurable PHP Calendar
PHP Calendar
PHP Image Processing
PHP grahic softwares
PHP create real-time dynamic chart
create antispam image(image verification)
Add water mark to image
PHP Image processing introduction
Add text on Image
Create thumbnail for image
Create image from text on fly
PHP code sample
PHP create dynamic PDF with FPDF
PHP create dynamic PDF with PDFLib
PHP create dynamic PDF with ClibPDF
Improved PHP configurable hit counter
Install phpMyAdmin,MySql, PHP
PhpMyAdmin export/import data
A simple PHP RSS feed reader
PHP include (SSI)
Working with Forms
PHP formmail Generator
Using phpMyAdmin Create Database
Insert Form Data into Database
Retrieve data from Database
Retrieve multiple records
Batch insert text using phpMyAdmin
Using phpMyAdmin insert binary file
Insert binary file using PHP code
Using form insert binary file into MySQL
Retrieve binary file from MySQL
Image hosting business in minutes
Send HTML mail in PHP
Send bulk emails in PHP
Polling/Rating System in PHP
Polling/Rating System in PHP(radio button)
Check visitor's IP address
Check reciprocal link
PHP tutorial
What is PHP?
Install PHP on Windows XP (part1)
Install PHP on Windows XP (part2)
PHP open and closing tags
PHP types
Logic Structures
Include files
Set cookie and delete cookie
Most often used MySQL functions



Printer Inkjet A Z lyricsLearn ChineseHome|PHP|Swing|HTML|JavaScript|ASP|JAVA|Forum|WebTip|Contact Us
Copyright © All rights reserved(new). Privacy|Copyright
designed by

Please help us cover the web site maintenance fee.
barcode scanner Thermal Printer credit card machine bar code printer