This is a script to add a Rating System (with 5, 7 or 10 Stars) to rate images, articles, videos, games, or any element in pages of your web site.
This Star Rating Script is made using Ajax technology, with JavaScript and PHP (with OOP), it can be included in any page (".html", or ".php"), but the server must run PHP.
The rating data can be saved in TXT files on the server, SQLite database, or in a MySQL database (using PDO).
The rated item, the number of the day, and the user (name or IP) are saved on the server, also in cookies, so, the user /visitor can rate again the next day.
You can use the script to add rating system to one or more elements in a web page.
If you have a register /login script in your web site, you can set this Rating Script to allow only the logged users to rate. By default, all the visitors can rate an element once to 24 hours.

• To Download it, click: Ajax-PHP Rating Stars Script.

• The script has 4 versions: Five stars with 10 numbers to vote (1, 2, 3, 4, ... 10), Five stars with 5 numbers to rate (1, 2, 3, 4, 5), Seven rating stars, and Ten rating stars.
It has been tested successfully on Mozilla Firefox, Internet Explorer, Google Chrome and Opera.
- Details about Installation and Settings you'll find in a "readme.html" file, in the archive with the script.
• It is indicated to put the script in the root directory of you website. If you copy it into a subfolder, see the instructions below.


In this Rating Script, the user can vote again an item next day.
If you want to set another time when the user can vote again, for example over 2 days, next week, or you want the user to can vote an item a single time only, use the PHP files from this archive:
    • Download: Rating Stars Script - Set Time

- Then, replace the "class.rating.php", "create_tables.php", and "ratings.php" with the files from this archive.
- See the comments in "ratings.php". Then access the "create_tables.php" to create the tables in MySQL or SQLite database.

With these php files, data can be stored only in MySQL or SQLite database.

Demo (move the cursor over the stars, and click to rate the following images):
Test Rating Script
Test Rate Script.
Rate Dolphin
Star Rating Script.

• If the rating data are saved in MySQL or SQLite database:
To create a list which ranks the score of multiple voted items, based on highest rating, perform a MySQL Select in the "rtgitems" table. This table stores the voted items (in "item" column), points (in "totalrate" column), and number of votes (in "nrrates" column).
Example:
SELECT `item`, (`totalrate` / `nrrates`) AS `rank` FROM `rtgitems` ORDER BY (`totalrate` / `nrrates`) DESC LIMIT 10

• If you want to use this Rating Script in pages that are in different folders, and the current settings not works, open the "ratings.js" file (in "ratingfiles" directory), and replace this code:
obajx.open("post", '/ratingfiles/ratings.php', true);

With this line of code (to use the absolute path to the "ratings.php" file):
obajx.open("post", 'http://'+ document.domain +'/ratingfiles/ratings.php', true);

If the "ratingfiles" folder is not in Root, delete the beginning "/":
obajx.open("post", 'ratingfiles/ratings.php', true);

Or, add the sub-folder name, with '/' from root::
obajx.open("post", '/subfolder/ratingfiles/ratings.php', true);

- Also, be sure to have in each page the correct path to the "ratings.css", and "ratings.js" files, included in the HTML code.

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which HTML5 tag defines marked text? (can be used to highlight parts of text)
<mark> <embed> <span>
<p>Free corses: <mark>coursesweb.net</mark> for Web Development.</p>
Which CSS pseudo-class adds a style to an element when the mouse is over it?
:focus :hover :active
a:hover {
  font-weight: bold;
  color: #00da01;
}
Click on the function which returns a string value that represents the number rounded to the x digits after the decimal point.
toPrecision(x) toFixed(x) floor(x)
var num = 12.34567;
num = num.toFixed(2);
alert(num);       // 12.35
Indicate the PHP function which reads an entire file into an array.
[) file() readfile()
$arr = file("a_file.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
var_export($arr);
Ajax-PHP Rating Stars Script

Last accessed pages

  1. Mahjong Gardens (7467)
  2. Create simple Website with PHP (16296)
  3. Associative Arrays in JavaScript (3714)
  4. Check the file type before Upload (6316)
  5. Get search data from URL address in JavaScript (1896)

Popular pages this month

  1. Qwop (5062)
  2. Drag Racer V3 (2444)
  3. Flash Games - Free online Games (1201)
  4. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (1065)
  5. Bubbles3 (1023)