Codeigniter, AJAX Voting/Rating System

We post tutorials, articles or blogs either to our own blog site or as a user to other sites. Sometimes we need to let user rate on our tutorials or articles or blogs so that we know how much that blog is famous or how much that blog is intended to be accepted by readers.

Here I am going to show you how we can implement a simple voting/rating system using AJAX, Codeigniter so that everyone will get an idea how to do it. In this example I have given one sample content on which you can rate this. The rating/voting system is calculated by taking average on accumulated votes on five stars. Once you give vote/rate from your system you cannot give vote or rate next time. As soon as you cast your vote or rate you can see it instantly the updated vote as well as you can also see what vote/rate you have cast. When you mouse over on stars you can see the highlighted stars on how many stars vote/rate you want to cast.

If you have any query please feel free to leave a comment.


Knowledge of PHP & Codeigniter, jQuery and AJAX
MySQL 5.x
Apache HTTP server 2.2, 2.4
Codeigniter 2.1.4, 3.0.6
Netbeans 7.x, 8.0.2

Project folder structure in Netbeans IDE

Codeigniter AJAX Vote/Rate System

You need to create assets folder in parallel to application folder for putting all asset files such as js, css, images etc.

Final Output

When you run the application

Codeigniter AJAX vote/rate system

When you mouse over stars

Codeigniter AJAX vote/rate system

When you cast your vote/rate
Codeigniter AJAX vote/rate system

Step 1. First thing is we need to create database table

Step 2. Once you have codeigniter framework setup in place then configure database settings at location application/config/database.php

Step 3. Create a assets helper file under /application/helpers/assets_helper.php which gives us the URL for different assets like css, js etc.

Step 4. Modify the autoload.php file at location application/config/autoload.php as follows

Step 5. Create a model which will give us the data for the vote/rate under application/models/blogmodel.php. The below model file is pretty simple.

Step 6. Now create one controller called BlogController under application/controller/blogcontroller.php with below code

Step 7. Now modify the application/config/routes.php file as follows

Step 8. Next create a view with the following code under /application/views/blog.php

Step 9. Download the assets directory and put it under project root directory


Step 10. Run the application.

Download source code here ci

That’s all. Thanks for reading.

17 Replies to “Codeigniter, AJAX Voting/Rating System”

  1. Hello i m running the project on localhost and when i rate it pop up a window javascript and gives me a message
    [object]/[object] and it doesn’t update the value..plz contact with me with e-mail to sent you a screenshot

      1. i have download the assets and i copy everything in my codeigniter and i build my sql as yours but i get that error i use the latest version of codeigniter 3

          1. I have tested the same code with Codeigniter 3, it is working fine. You must be doing something wrong. Please check your source code.

  2. Can you please give me your project?When I go to rate It’s always show me a screan [object] [object] and I can’t rate.I can’t solve the problem.So please can you give me this project?

Leave a Reply

Your email address will not be published. Required fields are marked *