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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple math problem

Status
Not open for further replies.

kpdvx

Programmer
Dec 1, 2001
87
US
I want to enable a simple voting system. I think it might work, but I would like some of you guys that are better at math to help me out. The user would get to vote on a scale of 1-10, meaning based on what they thought, they would click 1-10. MySQL would keep track of the total of votes (each users click would just be added to the sum in $rating, so if one user clicked 5, another clicked 4, and another clicked 7, $rating would equal 16) and the total number of votes counted ($num_votes), in the above example it would equal 3. So in order to find out the scale of 10 rating, the code would just divide $rating by $num_votes. In the above example, the final rating would be 5.3333 (how do I round in php?). My question is: will this always work, will i always recieve an answer <= 10? Thanks for any help.
 
yes ,

u will always get answer <= 10

for rounding the final rating to integer u can use floorround or ceil functions depending on ur requirment...

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top