Search code examples
phpmysqlvotevoting-system

PHP based voting script


I am working on a tube site that categorizes each video by its origin country other than just the category.

I need to think of a voting system that will allow users to correct us if we made a mistake with the country and possibly suggest the correct one. So I thought there would be this + / - simple voting system. If the user clicks '-' then he'll need to suggest the correct country.

Let's say we said the video is from Brazil, the user should be able to vote against and choose the correct country from a list and submit. Then we would need to correct it manually.

I just can't think of a way to create that option from the MySQL table angle. I mean there are 200 + countries in our DB, each has its ID and I was thinking of creating a table for the voting script: ID | video ID | Votes for | Votes Against | suggestions. I can't think of the logic to fit in a way to suggest several of countries (creating a column for each country is not an option here..). The problem is basically that each user can suggest a different country. For example: 5 could say it is Argentina, 2 could say it is chile, 4 say Spain etc. How can I design the table to take many values with a previously unknown number of them?

I'm not that good with Databases..

There are plenty of good voting scripts out there but non of them have the suggestion feature. At least none I could find.

If you know a good script that can fit here it's also great.

Thanks!


Solution

  • video table   
       video_id 
    
    
    votes table
       video_id
       proposed_country_id
       voter_id
    

    Then select video, proposed_country_id, count(proposed_country_id) join votes using( video_id ) group by video_id, proposed_country_id