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:
1 2 3 4 5 6 7 |
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; } } } |
1 thought on “Ajax Rating System: Create Simple Ajax Rating System using jQuery AJAX and PHP.”
Comments are closed.