I have a database of pictures, and votes. The pictures database has up_votes and down_votes culomns. I want to create a system using MySQL to get hot and trending pictures just like 9Gag.
How can I do that?
FarrisFahad 103 Junior Poster
Recommended Answers
Jump to PostYour hot or trending images should have a time eleme t to it too, as in 'only the last 3 days' for example. Otherwise the same old image could be top of the pops forever.
Jump to PostIt's not just the algorithm, as @alan.davies said, the data plays a part. Instead of storing up or down votes as integers, you probably need to introduce a new relation (let's refer to it as
Vote
) that has apost_id
and auser_id
which are foreign keys to theposts
…
Jump to PostI'd just add to pty's post that you may benefit from keeping some non-normalised fields that gets updated everyday - this can be done with a cron job, which keeps today's tops and all time tops. This all depends on the volume of votes you get though. I'll flesh out …
Jump to PostIf you're not even going to read the links I post there's no point in responding. The algorithms are even listed and annotated. You could convert that code to SQL quite easily, or do the heavy lifting in SQL and the ranking in PHP.
Nobody's going to spoonfeed you code.
All 13 Replies
rproffitt 2,701 https://5calls.org Moderator
FarrisFahad 103 Junior Poster
FarrisFahad 103 Junior Poster
rproffitt 2,701 https://5calls.org Moderator
FarrisFahad 103 Junior Poster
rproffitt commented: That's a good question. Most likely secret sauce. Or in those scripts you buy. +15
alan.davies 185 What's this?
FarrisFahad 103 Junior Poster
pty 882 Posting Pro
alan.davies 185 What's this?
FarrisFahad 103 Junior Poster
pty 882 Posting Pro
FarrisFahad 103 Junior Poster
pty commented: I'm glad it helped +9
pty 882 Posting Pro
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.