Skip to content
Coding India Lab
  • PDF Tools
    JPG to PDF

    JPG to PDF

    PNG to PDF

    PNG to PDF

    WEBP to PDF

    WEBP to PDF

    Protect PDF File

    Protect PDF File

  • Category

    SVG Converter

    • PNG to SVG
    • JPG to SVG
    • WEBP to SVG
    • AVIF to SVG

    SEO Tool

    • HTML Heading Checker
    • Word Counter
    • Keyword Density Checker
    • Internal Link Checker
    • Meta Tags Analyzer
    • Meta Tags Generator

    Excel Converter

    • Excel to XML
    • Excel to HTML
    • Excel to JSON
    • JSON to Excel

    Social Downloader

    • Instagram Reel
    • Facebook Reel
    • Facebook Video
    • YouTube Thumbnail
    • Vimeo Thumbnail

    Text Converter

    • Lower Case To Upper Case
    • Remove Duplicate Words
    • Auto Capitalize Sentences
    • Online Text Editor

    Colors Converter

    • Hex To Pantone
    • RGB To Pantone
    • RGB to HEX
    • CSS Gradient Generator

    WEBP Converter

    • JPG To WEBP
    • PNG To WEBP
    • WEBP To JPG
    • WEBP To PNG

    Minify Generator

    • CSS Minify
    • HTML Minify
    • JS Minify
  • Calculator Tools
    • Cubic Feet
    • Volumetric weight
    • KG to Pound
    • Length unit converter
  • Pages
    • About Us
    • Privacy and Policy
    • Terms and Conditions
    • Disclaimer
    • Contact Us
  • Blog

Dynamic Progress Bar in HTML, JS & PHP with source code

admin, December 23, 2024January 10, 2025

Clear Guide to Build Reviewing Progress Bar:

This bar will be viewed by an average rating of stars, with the number of stars and a progress tracker for each star rating; thus, it serves for review pages or dashboards.

Review Progress Bar:

Average Ratings: The average ratings display the average ratings of stars and numbers.
Rating Progress Bar: The number of users who rated the review with 1, 2, 3, 4, or 5.
Good Looking: Bright and modern design, so all clean and simple.

Step 1: Building HTML Structure

We will now create the skeleton of the HTML, which is a section for the average rating and a space for the progress bars.

HTML Code:

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Review Rating UI</title>
<link rel=”stylesheet” href=”https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css”>
</head>
<body>
<h1>Review Rating System</h1>
<div class=”average-class”>
<span class=”star-container” id=”average-stars”></span>
<span class=”average-rating” id=”average-rating”>Calculating…</span>
</div>
<div class=”progress-container” id=”progress-container”></div>
<script src=”https://code.jquery.com/jquery-3.6.0.min.js”></script>
</body>
</html>

Step2: Styling Progress Bar

So obviously, it should look good. Use CSS to style the stars, the progress bars, and the text.

CSS CODE

<style>
body {
margin: 0;
font-family: Arial, sans-serif;
background: linear-gradient(to right, #f8f9fa, #e9ecef);
color: #333;
}
h1 {
text-align: center;
font-size: 24px;
margin: 20px 0;
color: #444;
}
.average-class {
display: flex;
justify-content: center;
align-items: center;
gap: 20px;
margin: 20px 0;
}
.average-rating {
font-size: 20px;
font-weight: bold;
}
.stars i {
font-size: 24px;
color: gold;
}
.progress-container {
width: 80%;
max-width: 800px;
margin: 20px auto;
background: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.progress-row {
display: flex;
align-items: center;
margin: 15px 0;
}
.progress-bar-review {
flex: 1;
background: #f1f1f1;
border-radius: 20px;
overflow: hidden;
height: 30px;
margin: 0 10px;
position: relative;
}
.progress-review {
height: 100%;
line-height: 30px;
color: #000;
text-align: center;
white-space: nowrap;
font-size: 14px;
transition: width 0.4s ease;
}
.progress-review[data-rating=”5″] { background: #4caf50; }
.progress-review[data-rating=”4″] { background: #2196F3; }
.progress-review[data-rating=”3″] { background: #FF9800; }
.progress-review[data-rating=”2″] { background: #FF5722; }
.progress-review[data-rating=”1″] { background: #F44336; }
.count {
width: 50px;
text-align: right;
font-size: 14px;
}
@media (max-width: 600px) {
.progress-container {
width: 95%;
}
.average-class {
flex-direction: column;
gap: 10px;
}
}
</style>

Step 3: Dynamic Data Adding by jQuery

With js and jQuery, we can easily fetch the data and update the progress bar in real-time.

js code:

<script>
$(document).ready(function () {
$.ajax({
url: ‘yourpagename.php’, // Replace with your PHP file URL
method: ‘GET’,
dataType: ‘json’,
success: function (response) {
const { data, total } = response;

// Calculate the average rating
let sumRatings = 0;
for (let rating = 1; rating <= 5; rating++) {
const count = data[rating] || 0;
sumRatings += count * rating;
}
const averageRating = (sumRatings / total).toFixed(2);

// Display the average rating
$(‘#average-rating’).text(`${averageRating} Out of 5`);

// Render average stars
const fullStars = Math.floor(averageRating);
const halfStar = (averageRating % 1) >= 0.5 ? 1 : 0;
const emptyStars = 5 – fullStars – halfStar;

let starsHTML = ”;
for (let i = 0; i < fullStars; i++) starsHTML += ‘<i class=”fas fa-star”></i>’;
if (halfStar) starsHTML += ‘<i class=”fas fa-star-half-alt”></i>’;
for (let i = 0; i < emptyStars; i++) starsHTML += ‘<i class=”far fa-star”></i>’;

$(‘#average-stars’).html(starsHTML);

// Generate progress bars
for (let rating = 5; rating >= 1; rating–) {
const count = data[rating] || 0;
const percentage = ((count / total) * 100).toFixed(2);

$(‘#progress-container’).append(`
<div class=”progress-row”>
<span>${rating} Stars</span>
<div class=”progress-bar-review”>
<div class=”progress-review” data-rating=”${rating}” style=”width: ${percentage}%;”>
${percentage}%
</div>
</div>
<div class=”count”>(${count})</div>
</div>
`);
}
},
error: function (xhr, status, error) {
console.error(‘Error fetching data:’, error);
}
});
});
</script>

Step 4: Access the Database with PHP

Fetch ratings from the database and post via JSON into the PHP file.

php code:

<?php
$conn = mysqli_connect(‘localhost’,’root’,”,’yourdatabasename’);

if ($conn->connect_error) {
die(“Connection failed: ” . $conn->connect_error);
}
$sql = “SELECT columnname, COUNT(*) as count FROM review_table GROUP BY columnname”;
$result = $conn->query($sql);

$data = [];
$total = 0;
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$data[$row[‘columnname’]] = $row[‘count’];
$total += $row[‘count’];
}
}
$response = [
‘data’ => $data,
‘total’ => $total
];
header(‘Content-Type: application/json’);
echo json_encode($response);
$conn->close();
?>

Preview Progress Bar

Preview Process Bar

What is so Unique About This Progress Bar?

  • All these things are done in real time from the server.
  • Simple and clean design. Therefore, easy to understand at a glance.
  • Different ratings are shown with different colors for uniqueness.

Final Words

This is what you would get after just a little coding in PHP, JavaScript, and CSS – a very elegant bar of review progress that is tagged along with the site, as it clearly and nicely displays customer feedback. Try customizing it for your site.
Download File

php

Post navigation

Previous post
Next post

Comments (2)

  1. AmandaItarly1 says:
    February 27, 2025 at 10:26 pm

    Thank you so much buddy you make good article

    Reply
    1. admin says:
      February 28, 2025 at 4:33 am

      You are most welcome

      Reply

Leave a Reply Cancel reply

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

Recent Posts

  • How Do I Copy Text from an Image?
  • How do you merge two PDF documents into one?
  • How to Bulk Convert Images to WebP For Free?
  • How to create a QR code for free?
  • How to Calculate Interest Rate Per Month?
  • Convert HTML Table To JPG Image Using Javascript
  • Convert Images Into WEBP Free Unlimited
  • Convert JPG Image To WEBP Format Using PHP Mysqli JQuery
  • Create GIF Images Using HTML JQuery
  • Resize Your Images Online Unlimited
  • How To Change PNG To WEBP Using PHP JQuery
  • Image To Video Converter Using HTML JQuery

Categories

  • birthday wishes
  • html
  • jquery
  • php
  • seo
  • social
  • tools
  • WordPress

Social Tools

  • Facebook Reel Downloader
  • Facebook Video Downloader
  • YouTube Thumbnail Downloader
  • Vimeo Thumbnail Downloader

Image Converter

  • Bulk JPEG To WEBP
  • Bulk JPG to WEBP
  • Bulk PNG to WEBP
  • Bulk WEBP to PNG
  • Bulk WEBP Converter

Text Converter

  • Character counter
  • Remove Duplicate Words
  • Word Counter
  • Small Text Generator
  • Reverse Text Generator

PDF Tools

  • JPG to PDF
  • PNG to PDF
  • WEBP to PDF
  • Protect PDF file
©2025 Blog | WordPress Theme by SuperbThemes

Copyright © 2025 Coding India Lab. All rights reserved.