Ajax Visitor star rating scriptThis is a simple rating script where users are asked to rate an article in a scale of one star to five star.To understand this script you must have knowledge of PHP MySQL and Ajax concept. If you are not yet comfortable with Ajax then you can read the basic rating script using PHP and MySQL For Demo of this script , click the button towards the end of this page. Features of this rating script
Rating scale of 1 to 5 stars is opened in a new window with period buttons for users to select. On Selection the data will be added to table without refreshing the page ( Ajax ) and the window will close automatically. MySQL TableTo keep the script simple we have used one single table and here is the structure.
Unique Page name.Each page should have one unique identification number or page name and this is to be passed to our script as we are using common page to display the rating window.Integrating the rating pageFrom each page of your site you can integrate the rating window by including it.
Inside this common-tag2.php page we will keep the radio buttons to receive user selection. Each radio button is connected to Ajax function by onClick event and it passes the rating value to the ajax function.
rating-ajax.jsThis is the JavaScript file having the Ajax function inside. It receives two data from the main page. One is the user rating and other one is the unique page name. These two values will be posted to our backed script rating-window-ajax.php file for storing in database table.rating-window-ajax.phpThis file receives rating value and unique page name from JavaScript file. Then it insert the same to table by using pdo insert command.
Displaying the rating of pages ( display.php ).Displaying of rating is left to users to customize according to their requirement but we have given one simple query page display.php to display the total count of ratings and its average value. By clicking the page name users can see the all the ratings of that particular page.
Displaying the top fiveThis query page can be further modified to display the top rated pages, or getting the top five rated pages by adding order by and limit SQL commands to our above query.
Display rating scale in same page. ![]()
This article is written by plus2net.com team.
![]() | ||||
▼ PHP MySQL Scripts
| ||||