Does anyone know where I can find out how to add a "rate this song" to my site? I have been researching this and can't seem to find it. Thank you for any direction.
i'm not aware of any prebuilt code. perhaps because it is not difficult to do it yourself.
assume you are keeping the song titles in a db.
add a column to the table with called "rating"
add a form object to the page with the song on and within the form provide a unique identified for the song and a button called "rate" . you could also do this with a link and avoid the form overhead
in the receiving script trigger a sql query something like this
Code:
update songtable set rating = rating+1
if you want people to vote a number of rating (rather than a single vote) then something like this
Code:
$vote = (int) trim($_POST['rate']);
mysql_query("Update songtable set rating=rating+$vote");
if your plan is to have a 1-5 rating (or something similar), then it may be in your best interest to create a new table that would contain (at minimum) the song unique identifier and the rating amount for each rating submission.
you would then be able to determine the average rating by taking the sum of the ratings and dividing by the record count.
Re Cory's comment: I agree, his method with a separate table would give materially greater flexibility. use an insert query instead of an update as you would want to capture every vote to get a proper mean.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.