Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 07-27-2004, 08:13 PM Voting System..
Unknown.

Posts: 1,693
Trades: 0
I want to create a voting system so that the user rates the picture between 1 and 10...

Then it calculates an average from all the votes...

So it can display... 'Rating : average'

But then also list the top four rated pictures...
like..

Best Pictures
1. Imagename
2. Imagename
3. Imagename
4. Imagename

Anyone be able to help with the table structures and php??

Thanks

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-27-2004, 08:48 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
James, what I would do is not to store off the value of every vote and then recompute the average every single time.

Create a table called ratings:

pictureId <-- primary key
total <-- the total of all votes cast (e.g., 7,7,10,1,6 = 31)
votesCast <-- exactly that -- in the example above, 5.


So as a new vote is cast, retrieve the record for the picture, increment votesCast by 1 and total by the value of the vote.

You may even want (for faster searching) to have a fourth column already computing the average. In fact, I would recommend that (let's call it averageVote) so that you could then perform your SQL pulls based on that value:

PHP Code:
$sql "SELECT * FROM ratings ORDER BY averageVote DESC" 
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 07-27-2004, 09:09 PM
Unknown.

Posts: 1,693
Trades: 0
Thanks

How would I divide the total by the votescast?

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 07-27-2004, 09:10 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
$total / $votescast?

You've been here long enough to know how to grab info from the database
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 07-27-2004, 09:15 PM
Unknown.

Posts: 1,693
Trades: 0
Thanks

Thought it would be something like that... Just making sure

I always think of the hard way of doing stuff..good job theres people to help

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Voting System..
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.73202 seconds with 12 queries