1. Computing
Send to a Friend via Email

A Simple Rating System in PHP

By

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", 1, 1 )
Related Video
Basic PHP Syntax
Using PHP With HTML
  1. About.com
  2. Computing
  3. PHP / MySQL
  4. Step By Steps
  5. Simple PHP Rating Script

©2014 About.com. All rights reserved.