How to take votes and rank images using PHP and MySQL

I'm trying to build a php ranking system for images. As soon as the user clicks on the image it gets upvoted by 1. Depending on how an image is ranked decides what its place on the leaderboard (rank number) would be. The rank should change depending on the different ratings it receives from users. I want to keep ranking ip based as in like no same user can vote twice.  I have written the frontend code for the same.

Would integrate it if needed.
sanchit guptaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
We have an article here about voting and ranking.  It probably contains most of the moving parts you would need.
https://www.experts-exchange.com/articles/5256/Simple-Vote-Counting-in-PHP-and-MySQL.html
0
sanchit guptaAuthor Commented:
@Ray Doing that with images would be a little different. Could you please write an article for the same?
0
Ray PaseurCommented:
This expert suggested creating a Gigs project.
I think any knowledgeable and experienced developer could help you bridge the gap between the article (clicking a checkbox) and your needs (clicking an image), so I recommend you use E-E Gigs and find a developer who can help you.

To the part about "no same user can vote twice" you will get uneven results if you use the IP address as the gating factor.  What if a user is on AOL, where the IP address changes from request to request?  What if the user is in an office, where everyone communicates through a server with the same IP address?  If you're willing to accept these risks, just mark the IP address column UNIQUE in your table of votes.  When an attempt is made to insert a duplicate value, MySQL will not insert the duplicate and will return errno=1062.  Your application can trap this error and take whatever action you want.  One thought might be to request a payment before entering another vote.
1
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

sanchit guptaAuthor Commented:
gigs project cost money
1
Ray PaseurCommented:
Of course Gigs cost money!  Why?  Because they're worth it.  

You get value from the help of a knowledgeable and experienced developer.  The alternative is for you to take the time and effort to learn everything a developer already knows, and then do the work yourself.  Even in a concentrated learning environment such as a university, you would need months to learn what you're asking me to write an article about.  If I had the "free time" to write the article, I would consider it.  But the truth is that all of the information a developer would need is already in the article about vote counting.

If you're new to PHP and want to learn the language, this article can help.  It will show you good learning resources and help you avoid the many dangerous, outdated and incompetent PHP examples that litter the internet.
https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Hi sanchit.  I think the disconnect with Ray is for something like this we probably are not going to write out an entire program.  But we can help you.  I suggest breaking your request to multiple questions where this first question only goes over how this is done.   From there you can work on the individual parts and ask separate questions for each where you show what you have so far or where you need help to get started.

In very simplistic terms, this can work by:

1) Create a database with 2 tables.  One table will have an id, image name and image description.  Let's call this table, 'tblImages'.  Your 2nd table will be a transaction table that tracks each upvote.  This table will have one field called image_id and lets call this table, tblImageUpVotes.  

For now, we are keeping this simple. Complexity can be added later.

2) For this example, let's assume you have a finite number of images that you uploaded to your server and have also added to your tbleImages.

Again, more advanced features will be uploading images and adding that to the db.  But for now, we keep it simple.

3) Create a simple HTML page that displays all the images with an html table at the top that contains the leader board of upvotes.

4) Each time an image is clicked, we want to add the image id (from the database) to our transaction table called tblImageUpVotes.  In the end, this table will be filled with a bunch of id's.

5) To figure out which image has been clicked the most, we create a group by query that counts the id's https://dev.mysql.com/doc/refman/5.7/en/group-by-modifiers.html

6) We will place use the group by query and sort it by the count in descending order and display that on our leader board.


This is a very basic outline and if this sounds similar to what you want to work with, let's iron out the overview here in this question.  Then you can ask specific questions for each of the steps.
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Also, you will see when you do accept answer(s) for this thread, there will be an, "Ask a related question" button.  That will link this question to your next.  Keep doing that for each of the steps and that will give the Experts a way to reference what has already taken place.
1
Ray PaseurCommented:
abandoned question - hopefully taken up in Gigs
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.