Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Rate This Song" php code

Status
Not open for further replies.

webmaniacal

Technical User
Aug 24, 2006
47
US
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");
 
from a database perspective, i disagree.

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.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top