Ajax Rating System: Create Simple Ajax Rating System using jQuery AJAX and PHP.

Written By: Zeeshan Rasool  |  Posted In: AJAX, JQuery, PHP, Web Development

Simply programmed, CSS based stylish Ajax rating system which you can use any where to put a stylish jquery effect based rating system.

Table Structure:

CREATE TABLE `ajax_ratings` (
  `id` int(11) NOT NULL auto_increment,
  `image_id` int(11) NOT NULL default '0',
  `rating` int(11) NOT NULL default '0',
  `users_ip` varchar(200) NOT NULL default '',
  PRIMARY KEY  (`id`)
)

Javascript Code:

$(document).ready(function(){	
	$('#loader').hide(); 
	$('#inner').children().click(function(){
		var a = $(this).attr("id");
		$.post("rating.php?value="+a, {
		}, function(response){
			$('#inner').fadeOut();
			$('#inner').html(unescape(response));
			$('#inner').fadeIn();
			setTimeout("hideMesg();", 2000);
		});
	});	
});	
	
function hideMesg(){

	$('.rating_message').fadeOut();
	$.post("rating.php?show=1", {
	}, function(response){
		$('#inner').html(unescape(response));
		$('#inner').fadeIn('slow');
	});
}	

PHP Code

include("dbcon.php");
$users_ip = $_SERVER['REMOTE_ADDR'];
if($_REQUEST['value'])
{
	$id = $_REQUEST['value'];
	$result = mysql_query("select users_ip from ratings where users_ip='$users_ip'");
	$num = mysql_num_rows($result);
	
	if($num==0)
	{
		$query = "insert into ratings (rating,users_ip) values ('$id','$users_ip')";
		mysql_query( $query);
		
		$result=mysql_query("select sum(rating) as rating from ratings");
		$row=mysql_fetch_array($result);
		
		$rating=$row['rating'];
		
		$quer = mysql_query("select rating from ratings");
		$all_result = mysql_fetch_assoc($quer);
		$rows_num = mysql_num_rows($quer);
		if($rows_num > 0){
		$get_rating = floor($rating/$rows_num);
		$rem =  5 - $get_rating;
		}
      }
}


If you enjoyed this post, please consider leaving a comment below or subscribing to the RSS feed to have future articles delivered to your feed reader. You can also follow us on Facebook or Twitter @99Points


Zeeshan Rasool is the founder and editor of this blog. Beside this, he is an experienced PHP web developer and freelancer. He loves to create best and interactive web apps. You can follow him at twitter @99_Points and facebook OR drop an email at 99points.info@gmail.com

72 to “Ajax Rating System: Create Simple Ajax Rating System using jQuery AJAX and PHP.”

  • Super Ajax Polling/Voting System using JQuery, Ajax, PHP and MySQL August 29, 2011 at 11:03 am

    [...] system or Voting system is very common in web sites. Voting can be about your site or blog or some other thing just to get [...]

  • New Ajax Star Rating System in Tag Cloud Style using JQuery and PHP | Nubis Design August 30, 2011 at 2:50 pm

    [...] tutorial in Rating System series is here for you. It is a stylish and animated rating system I created many Ajax based Rating [...]

  • Information Systems Talk » Super Ajax Polling/Voting System using JQuery, Ajax, PHP and MySQL September 10, 2011 at 9:05 pm

    [...] system or Voting system is very common in web sites. Voting can be about your site or blog or some other thing just to get [...]

  • Super Ajax Polling/Voting System using JQuery, Ajax, PHP and MySQL | Webdesign September 21, 2011 at 4:50 am

    [...] system or Voting system is very common in web sites. Voting can be about your site or blog or some other thing just to get [...]

  • New Ajax Star Rating System in Tag Cloud Style using JQuery and PHP | Webdesign September 21, 2011 at 2:00 pm

    [...] tutorial in Rating System series is here for you. It is a stylish and animated rating system I created many Ajax based Rating [...]

  • New Ajax Star Rating System in Tag Cloud Style using JQuery and PHP | New Host Name September 27, 2011 at 5:32 pm

    [...] tutorial in Rating System series is here for you. It is a stylish and animated rating system I created many Ajax based Rating [...]

  • Super Ajax Polling/Voting System using JQuery, Ajax, PHP and MySQL | Nubis Design September 27, 2011 at 5:58 pm

    [...] system or Voting system is very common in web sites. Voting can be about your site or blog or some other thing just to get [...]

  • Super Ajax Polling/Voting System using JQuery, Ajax, PHP and MySQL | New Host Name September 29, 2011 at 9:49 am

    [...] system or Voting system is very common in web sites. Voting can be about your site or blog or some other thing just to get [...]

  • Super Ajax Polling/Voting System using JQuery, Ajax, PHP and MySQL | YouThinkYouCare.com October 6, 2011 at 11:01 pm

    [...] method or Voting method is really widespread in internet internet sites. Voting can be about your internet site or weblog [...]

  • Super Ajax Polling/Voting System using JQuery, Ajax, PHP and MySQL | make-money-via-fb.info October 11, 2011 at 8:44 am

    [...] system or Voting system is very common in web sites. Voting can be about your site or blog or some other thing just to get [...]

  • RK January 17, 2012 at 7:53 pm

    Dude Update table name “ratings” to “ajax_ratings”. Because in you MySQL query you are creating a table named “ajax_ratings”.

  • codie January 27, 2012 at 12:15 pm

    hey can u provide me this rating system in codeigniter.???
    thanx in advance…..

  • codie January 27, 2012 at 12:20 pm

    hey can u customize dis module in codeigniter??plz do it….

  • ZeeShaN January 27, 2012 at 12:29 pm

    hi Codie, I will write a tutorial in Codeigniter later in the next month.

  • polas April 18, 2012 at 2:28 pm

    I get errors in index.php and i do not know how to fix it

  • tochukwu May 21, 2012 at 9:44 pm

    hi, i’ve been trying to incorporate this script into my site where i want to show products with this ratings attached..i’ve tried sincerely but i seem to be getting everything wrong please what do i do

  • tochukwu May 22, 2012 at 3:43 pm

    hi, please how do i call up both product and rating from mysql dynamically.

  • Lil July 9, 2012 at 1:44 am

    This rating system is very nice. A note to others who try it: you will need to update the index.php and rating.php scripts:
    change the reference to table name ratings to ajax_ratings. And in some places you will need to change the field name ratings to rating.
    Otherwise, works great, really is nice and simple!

  • gökhan September 21, 2012 at 9:15 pm

    Hi ZeeShaN I want to ask a question to you. This script is working perfect bu I want to do this. How can İ write to database my image id that I voted? Can you help me for that?

  • arti shrivas October 16, 2012 at 12:05 pm

    i want star image in place of box how can i achieve it can you help me i don’t know about jquery and java script

  • Jhun Rey January 12, 2013 at 11:54 am

    Hi! This site is a big help for me since I am creating a website. Thanks to your tutorials. However, this particular demo tutorial doesn’t work anymore. Please do fix this one. Thanks a lot again.

  • sarvan April 19, 2013 at 6:50 am

    an error -

    Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\starrating\index.php on line 41

    Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\starrating\index.php on line 46

    Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\starrating\index.php on line 47

    please chek then upload full working with source file …………………..

Post comment


Email Subscriber!

Be the first to know about new updates


Advertisement

Categories

Popular post

Recommend