PHP 5 Star Rating system with jQuery And AJAX

Admin   HTML5 - CSS   253  2021-03-13 00:00:08

Hi Guys

In this blog, I will learn you how to create 5 star rating system with jquery, ajax, and php. We will show example of php 5 star rating system with jquery and ajax.The star rating bar allows the user to submit his thoughts on whether the content or product is useful or not. This also gives the administrator a view of how well its item is performing.

Whenever the user changes the rating then send an AJAX request to save the user currently rating status on the MySQL database table with PHP.

Here, I will give you full example for simply display 5 star rating system with jquery, ajax, and php. as bellow.

1: Create Table

I n this step, I will create mysql in two table create posts and post_rating.

posts Table

 

CREATE TABLE `posts` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`title` varchar(100) NOT NULL,

`content` text NOT NULL,

`link` varchar(255) NOT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1;

post_rating Table

 

CREATE TABLE IF NOT EXISTS `post_rating` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`userid` int(11) NOT NULL,

`postid` int(11) NOT NULL,

`rating` int(2) NOT NULL,

`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1;

2: Configuration

Now In this step,I will Create a config.php for the database connection.