I have an image gallery with a vote function, and I’m trying to display the number of votes for each image from the database.
I have a Votes table with the following…
vote_id │ user_id │ session_id │ ip │ created_date │ status
I am trying to get the number of votes for each image to display (several images per page), but only 1 vote per ip and only within the last week (Mon to Sun).
I’m not a genius when it comes to this sort of thing, but this is what I have been able to do so far to get results in SQL. I’ve been getting a bit stuck trying to implement it into PHP…
SELECT COUNT(DISTINCT ip) AS Votes FROM 'vote' (I know its basic but there you go)
Here is 🙂
SELECT COUNT(DISTINCT ip) AS Votes, WEEK(created_date) AS week_num FROM 'vote'
group by WEEK(created_date)
order by week_num DESC