Build a website fast with GoDaddy.com! - 125x125
May
23

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

Author ZeeShaN    Category AJAX, JQuery, PHP, Web Development     Tags ,

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$(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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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;
		}
      }
}

Add To Facebook Stumble This Digg This Add To Del.icio.us Add To Reddit Add To Yahoo Add To Twitter


Written by ZeeShaN

ZeeShaN RasooL is a web developer who loves to work in latest technologies to create more interactive dynamic and beautiful web pages.

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

Post comment



Enter your Email:

Click Here for Popular

Who Am I

Zeeshan Rasool

Software Engineer - PHP
Lahore - Pakistan
Skype: zeeshan-rasool
gTalk: zishan.rasool85

Categories

Archives

Tags

99points adobe AJAX ajax pagination ajax rating ajax tutorial captcha Codeigniter codeigniter 2.0 codeigniter recaptcha CSS css tutorials curl dreamweaver cs5 Facebook Facebook. PHP. JQuery facebox farmville ffmpeg flv google api hacking image gallery Joomla JQuery jQuery Sliding Jquery tutorial mafia war Mootools MySQL Payment PHP php curl Poll System recaptcha RSS Feed SEO simplepie socail networking ssl Tutorials Twitter Web XSS youtube

Comments