how to create the mechanism like the photo attachs in this post.....to let user rating their view on something like DVD, VCD and etc
Printable View
how to create the mechanism like the photo attachs in this post.....to let user rating their view on something like DVD, VCD and etc
That could easily be done in PHP :).
can give the idea or the concept?? and the "*" star graphic??
Its quite simple, something like this.Quote:
Originally Posted by kenny_oh
1. Display dropdown / form with unique location for each one to be rated.
2. User selects andoption and clicks submit.
3. Check users IP has not rated this already. If it has stop the process if not continue.
4. Get the total number of people that have noted and the cumulative note they have mae.
5. Work out the average per person.
6. Work out the level (star) boundaies and then assign as many images as are required.
And thats aboutit I think :
Cheers,
Ryan Jones
hmmm.....i get the idea alr........but how to make the star images on, when user click for rating?
Probably AJAX, each star has an ID, when clicked it is sent andthen PHP recieves and processed it - it replaced the dropdown menu from my idea :)Quote:
Originally Posted by kenny_oh
Cheers,
Ryan Jones
AJAX is overkill for something like that..
here is some mockup PHP code that could be used:
//query DB and find the number of ratings, users ect...
switch ($rating) {
case 0:
//no rating
break;
case 1:
//1 star rating
break;
case 2:
//2 star rating
break;
}
Actually its perfect for this job, it allows live rating - without needing a form and a page refresh.Quote:
Originally Posted by k1ll3rdr4g0n
Cheers,
Ryan Jones
Indeed, however you should not rely on it so provide a form as well and hide that through JS code. If the browser does not suport JS then the form will be shown.
The general idea for the DB side of it is to store the total number of votes and the total number of vote values. That way you get the average rating from each user.
Example:
A user rates as a 3 - Total votes is 1 and total count is 3, average is 3
another user rates as 1 - Total votes is 2 and count is 4, average is now 2.
Sample PHP/MySQL code for the file that receives the update request (via POST would be the preferred option):
PHP Code:$id = (int)$_POST['item_id'];
$userRatings = mysql_fetch_assoc(mysql_query(
'SELECT `total_votes`, `total_count` '.
'FROM `user_ratings` WHERE `item_id` = '.$id
));
$votes = $userRatings['total_votes'] + 1;
$count = $userRatings['total_count'] + $_POST['vote_value'];
mysql_query(
'UPDATE `user_ratings` '.
'SET `total_votes` = '.$votes.', `total_count` = '.$count.' '.
'WHERE `item_id` = '.$id
);