5 star rating in PHP with AJAX and jQuery

5 star rating in PHP with AJAX and jQuery

Displaying a star ranking system is a common requirement to implement in websites. We have explained here how can we show a group of stars for each database record and dynamically apply 5 star rating in PHP with AJAX and jQuery. You can make AJAX calls to store rating of the record in database.

Download Complete Code

5 star rating in PHP with AJAX and jQuery

The code below is part of our PHP script which fetches records from database and displays star rating as per already saved rating of each post. 

jQuery to manipulate rating

We are using very handy jQuery script to manage user action on stars and to save rating through AJAX on click. We are using jQuery’s powerful ‘data- ‘api in the handy piece of functions written in rating.js file.

PHP MySQL star rating update via AJAX

This PHP code will be executed via an AJAX request received from browser. This code runs an update query by receiving id of post and current rating from AJAX. 

Download Complete Code for 5 star rating in PHP & MySQL

You Might Interested In

  • PHP Lerner

    Hello this what exactly i needed but when i run this code so it shows an PHP error
    Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:wampwwwtestratingdbmanager.php on line 16
    so can you update this code with new syntax of PHP MySql .. Plz

    • Amit Sonkhiya

      Hi, This is not a trivial task. I encourage you to look into dbmanager.php and replace mysql driver functions with PDO or mysqli driver function in connectDB, selectDB and rest 3 too
      for example:

      $conn = mysql_connect($this->host,$this->user,$this->password);

      with

      $conn = mysqli_connect($this->host,$this->user,$this->password);

      Ref: http://www.w3schools.com/php/php_ref_mysqli.asp

  • mukesh

    how to insert in to data base plz help

    • Amit Sonkhiya

      Hello,

      You can download the source and there is add_rating.php file, which is updating rating of given post in database. What do you mean by insert in this case?