Simple php rating system with database Example

Today, We want to share with you php rating system with database.In this post we will show you simple star rating using php, hear for display star rating from database in php we will give you demo and example for implement.In this post, we will learn about Simple PHP Rating System with database using JavaScript with an example.

Rating and review system in PHP and MySQL

process.php

<?php
$servername='localhost';
$username='root';
$password='[email protected]';
$dbname = "app_live_v1";
$conn=mysqli_connect($servername,$username,$password,"$dbname");
if(!$conn){
	die('Sorry, Could not Connect My Sql:' .mysql_error());
}
$query = mysqli_query($conn,"SELECT AVG(simple_rating_system) as AVGRATE from product_reviews where status=1");
$row = mysqli_fetch_array($query);
$AVGRATE=$row['AVGRATE'];
$query = mysqli_query($conn,"SELECT count(simple_rating_system) as Total from product_reviews where status=1");
$row = mysqli_fetch_array($query);
$Total=$row['Total'];
$query = mysqli_query($conn,"SELECT count(remark) as Totalreview from  product_reviews where status=1");
$row = mysqli_fetch_array($query);
$all_reviews=$row['Totalreview'];
$review = mysqli_query($conn,"SELECT remark,simple_rating_system,email from product_reviews where status=1 order by date_time desc limit 4 ");
$simple_rating_system = mysqli_query($conn,"SELECT count(*) as Total,simple_rating_system from product_reviews group by simple_rating_system order by simple_rating_system desc");
?>

index.php

<?php
	include'process.php';
?>
<!DOCTYPE html>
<html>
<head>
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
	<link rel="stylesheet" href="css/style.css">
	<link rel='stylesheet' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css'>
	<link rel='stylesheet' href='http://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css'>
	<link rel='stylesheet' href='https://raw.githubusercontent.com/kartik-v/bootstrap-star-rating/master/css/star-rating.min.css'>
</head>
<body>
<div class="row container dsp">
<div class="col-md-4 ">
	<h3><b>Final Rating & Reviews</b></h3>
	<div class="row">
	
		<div class="col-md-6">
			<h3 align="center"><b><?php echo round($AVGRATE,1);?></b> <i class="fa fa-star" data-simple_rating_system="2" style="font-size:20px;color:#ff9f00;"></i></h3>
			<p><?=$Total;?> ratings and <?=$all_reviews;?> reviews</p>
		</div>
		<div class="col-md-6">
			<?php
			while($product_rev= mysqli_fetch_array($simple_rating_system)){
			?>
				<h4 align="center"><?=$product_rev['simple_rating_system'];?> <i class="fa fa-star" data-simple_rating_system="2" style="font-size:20px;color:green;"></i> Total <?=$product_rev['Total'];?></h4>
				
				
			<?php	
			}
				
			?>
		</div>
	</div>
	<div class="row">
		<div class="col-md-12">	
		<?php
			while($db_review= mysqli_fetch_array($review)){
		?>
				<h4><?=$db_review['simple_rating_system'];?> <i class="fa fa-star" data-simple_rating_system="2" style="font-size:20px;color:green;"></i> by <span style="font-size:14px;"><?=$db_review['email'];?></span></h4>
				<p><?=$db_review['remark'];?></p>
				<hr>
		<?php	
			}
				
		?>
		</div>
	</div>
		
	
	<div id="simple_rating_system_div">
				<div class="star-rating">
					<span class="fa divya fa-star-o" data-simple_rating_system="1" style="font-size:20px;"></span>
					<span class="fa fa-star-o" data-simple_rating_system="2" style="font-size:20px;"></span>
					<span class="fa fa-star-o" data-simple_rating_system="3" style="font-size:20px;"></span>
					<span class="fa fa-star-o" data-simple_rating_system="4" style="font-size:20px;"></span>
					<span class="fa fa-star-o" data-simple_rating_system="5" style="font-size:20px;"></span>
					<input type="hidden" name="whatever3" class="simple_rating_system-value" value="1">
				</div>
	</div>
</div>
</div><br>
<input type="hidden" name="demo_id" id="demo_id" value="1">
<div class="col-md-4">
<input type="text" class="form-control" name="email" id="email" placeholder="Email Id"><br>
<textarea class="form-control" rows="5" placeholder="Write your review here..." name="remark" id="remark" required></textarea><br>
<p><button  class="btn btn-default btn-sm btn-info" id="srr_simple_rating_system">Submit</button></p>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="js/index.js"></script>

</body>
</html>

I hope you get an idea about how to show average rating in php?.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Read Also:  Get Parent Elements With CSS and jQuery

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

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