Visitor rating script in one to five scaleAfter reading an article visitors can submit rating or give feedback on the quality of the article by selecting a radio button.. This feature is quite common in various content management systems where user of visitor feedback is taken for assessment of the news or blog posting. Here we can ask the visitor to give feedback by writing comments or we can ask them to simply rate the article in 1 to 5 scale. Here we will discuss how to develop such a script to take care of ratings submitted by the visitors.
This can also be uses a part of a picture rating script where visitors can submit ratings for the photos.
This is a basic script using PHP MySQL, you can read advance rating script using PHP MySQL & Ajax hereThe script for content rating scripts has three main parts. One is displaying the form at the end of the article page. Second one is processing the submitted ratting of the visitor, third part is the displaying the average value of ratings given. We will try to keep these three parts in three different pages and we will include them from our content pages. This way maintaining the code became easy. For any modification we can change the script at a central location. We will include these three files in our content pages like this.
You can see the first line requires a content ID to identify the page in which it is connected. As we will be storing the rating in a database table so we need a system to identify each page with its rating, so the content ID will take care of this, here the content id is kept as a number to establish a link between our content management script and this rating script. In your case you can keep this as varchar field to store characters also. You have to take care that this filed must be a unique field as we can't store duplicate content id here.
Displaying the rating form: rating.phpThis is taken care by rating.php file. This file is included by all pages where form for submitting rating is required. This form uses one hidden tags todo is used to trigger the form processing script kept inside ratingck.php file. In this page period ( radio ) buttons are used to collect the visitor rating. There are five radio buttons to collect rating in the range of 1 to 5. For better clarity star images are used by the side of the radio buttons. Here each radio button is provided with onclick event to submit the form. Once the form is submitted the rating is handled by ratingck.php page.
Handling the form inputs: ratingck.phpOnce the form is submitted the rating of the visitor is collected and then it is checked if the record for this page ( identified through cont_id) is already exist. If the record is not there then a new record with current rating is submitted. If the record is already there then the data ( record ) is updated. While updating the record we have to store total number of ratings given in the field nov and then add the present rating to old rating stored in the record. Each time we add a rating we will increase the number of vote filed ( nov ) by one.
This article is written by plus2net.com team.