1. Home
  2. Computing & Technology
  3. PHP / MySQL

A Simple Rating System in PHP

By Angela Bradley, About.com

1 of 3

The Database

PHP Rating System

A simple PHP rating system

Angela Bradley
There are many uses for a rating script online. People love to have their opinion heard. You can rate photos, books, links to sites, etc etc. This tutorial will teach you how to make a simple rating script that you can customize for your needs, and easily expand upon.

Before we begin we need to create a MySQL database table to hold the ratings information. We are only creating four fields: a unique ID, the name of what we are rating, and 2 columns to hold voting information. You can create more fields if needed, for example if you are rating photos you may want to include the photos URL, the author, a description, etc etc.

CREATE TABLE vote (id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(30), total INTEGER, votes INTEGER)
We will also need to put some data into the database to work with. You could use this tutorial if you wanted to add new information directly from your browser, however here we will assume you already have a method in place for adding new options. The SQL below will just fill in the table with some sample data to work with.
INSERT INTO vote (name, total, votes) VALUES ( "First item", 45, 10 ), ( "Second item", 15, 4 ), ( "Third thing", 25, 7 ), ( "The Forth", 20, 5 ), ( "Fifth Thing", 0, 0 )

Index: A Simple Rating System in PHP

  1. The Database
  2. Voting and Results
  3. Processing Votes

1 of 3

Explore PHP / MySQL

More from About.com

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Step By Steps
  5. Rating Script - PHP Rating Script - Rate Script PHP

©2008 About.com, a part of The New York Times Company.

All rights reserved.