Multiple user, multiple entry voting system theory

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Multiple user, multiple entry voting system theory

Post by robster »

hi all :)

I have requested thought on my database design and processing ideas in this thread: viewtopic.php?p=82703

My website that this is going to go into is http://10secondclub.net

What I'm interested in reading here is what people think of my php logic.

soooo, on that note :)


The logic (or lack of)

Imagine I have a table called VOTING, it has these fields:
ID - UserID - EntryID - Rating - Month - Year

I also have a table called Entries where all the entries already reside, so each entry has these fields (amongst others):
ID - UserID - Rating - RatingAVG


1-Is user logged in?
2-If yes, then get their member id and stick it in $Uid
3-Parse thru the VOTING table where month is the same as the voting month AND year is the same as the voting year to see if the user has voted for this month.
4-If the user has NOT voted, then display the 1-5 rating box under each thumbnail
5-If the user HAS voted, then let them know they have voted under each thumbnail and what they voted (if they chose other than DO NOT VOTE. IE: 1, 2, 3, 4 or 5).
6-If user presses the vote button the voted for items get added to the database, the DO NOT VOTE items do not get added to database to save on space in database. These items are all added at ONE entry into the database per rating. So, if user 10 voted for 5 animations and gave them ratings it could look like this:

ID - UserID - EntryID - Rating - Month - Year
1 - 10 - 3 - 5 - 1 - 2004
2 - 10 - 7 - 3 - 1 - 2004
3 - 10 - 25 - 4 - 1 - 2004
4 - 10 - 31 - 5 - 1 - 2004
5 - 10 - 34 - 4 - 1 - 2004

At the end of the round, I use an admin panel to collate votes, and copy the ratings and create an average rating for each entry in the VOTING table that matches the month and year and copy them to the appropriate fields in the ENTRIES table. Another part of the code then displays this appropriately.


Now the code Logic (again, possible lack of ;))

1- Is user logged in? (I already have code for this). If user is logged in I place their userid in a variable called $Uid.
2- Open database and table connections (for ENTRIES table), count full number of entries and stick it in a variable called $total.
3-Use variable $total to loop through a loop. In loop display thumbnails for each entry in the database that are to be voted on (we check if their month and year values are the same as the current round we are voting on).
4- Whilst displaying the thumbnails in this current loop we start another loop that searches through the VOTING table and checks if $Uid matches $UserID and therefore has already voted for the current item (EntryID).
5- If the user HAS voted for the item, then let them know they have voted under each thumbnail and print what they voted (if they chose other than DO NOT VOTE. IE: 1, 2, 3, 4 or 5).
6- If the user has NOT voted, then display the 1-5 rating box under each thumbnail so they can choose a rating.
7-Now the thumbnails are displayed on screen with little choice boxes under each one. If the user presses submit it then goes backstage to do the mojo

Mojo
ERM, I'm stuck. :|
I need a way to have, say, 40 items' worth of formdata sent to code that adds the info to the database. I described this at the start of this thread.
Also, one user may only vote for 3 items and another 15 items. How do I account for that?

I really appreciate anyone's thoughts on this. It's the most exciting and ambitious part of my site and I want to take my time to get it right. Any feedback anyone can give is going to be well recieved and I'll take it all and work through what you have to say.

Thanks again :)

Rob
ilovetoast
Forum Contributor
Posts: 142
Joined: Thu Jan 15, 2004 7:34 pm

Post by ilovetoast »

Well, I'm watching a hockey game while answering, so I hope I'm responding to your actual question...

To start you, set the form up so it comes into the script a one big array. Easy enough to do....

Then just step through the array one element at a time. Pass each element to a function that evaluates, based on the contents of the element, whether a vote was made, what it was, etc. and then puts it in the db. You can have it just skip non-votes.

The array-loop should allow 40 items's worth of formdata + and the function will serve the role of sorting between the user who votes*3 and the user who votes*15.

peace

toast and butter
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

The foundation of most php programs is a properly normalised relational database design (I deliberately said "properly" and not "fully"..).

This explains it all: http://www.oreilly.com/catalog/javadtab ... r/ch02.pdf

If you like, check that out and post again with your plans.

PS: do you really want to make a new table row for each vote (thus logging who voted for what) or do you just want to log the tallies?
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post by robster »

Wow, two very informative replies. Thanks so much! :)

I'm reading the pdf now McGruff, thanks a load. Very informative.

ilovetoast, I'm about to invistigate your methods. Its a good sounding idea, I just need to get my head around it as Arrays are admitadly the most scary thing I know (I'm an animator, learning php/database design etc).

Forms I'm getting quite used to but am unsure how I can get a form in an array. Very abstract to my current knowlege level.

For display of the voting elements themselves I already have the thumbnails displaying for the entries waiting to be voted on. What I am thinking of now doing is THIS) - when the thumbnail is displayed in the thumbnail display loop launch another loop inside it that scans the VOTING table and checks if user has voted... if so, display what that user voted on that anim, if not, display the voting box (0-5).

I am thinking now, after reading your thoughts on a function that perhaps a function would be best to write and insert into the thumbnail display code.

Seeing as I need to take this one step at a time I will perform this first then come back and look into your suggestions further.

Wish me luck! :)

Thanks again.

Rob
Post Reply