Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5988199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:55:31+00:00 2026-05-22T22:55:31+00:00

With PHP and MySQL I am trying to display items with most votes over

  • 0

With PHP and MySQL I am trying to display items with most votes over a certain period of time (24 hour, 1 week, 1 year, etc). When someone votes on an item, a table records the user, item id, vote, and time, like so:

Table1

username |  itemid | vote | time
   asdf  |    127  |   1  |  1306726126
   asdf  |    124  |  -1  |  1306726123
    bob  |    127  |   1  |  1306726129
    bob  |    124  |   1  |  1306726123

Now, I have another table with item details.

Table2

itemid  | name  | category | date | etc

What I WANT to do is call a table to display all the data from table 2 for only items with votes in the last 24hours and sort it by the votes. This means I need to SUM votes with TIME < 24 hours, then RIGHT JOIN (?) to my other database? I don’t know, I am having difficulty figuring out how I should go about doing this. Any suggestiongs?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:55:32+00:00Added an answer on May 22, 2026 at 10:55 pm

    Something like this should work.

    SELECT SUM(Table1.vote) as votes, Table2.* FROM Table2            
        LEFT JOIN Table1 ON Table1.itemid=Table2.itemid                
        WHERE Table1.`time`>=DATE_SUB(Table1.`time`, INTERVAL 24 HOUR) 
    GROUP BY Table1.itemid                                             
    ORDER BY Table1.votes DESC  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to display from a MySQL Database using PHP and Ajax but
Using PHP and MySQL, I have a forum system I'm trying to build. What
I'm trying to write a page that calls PHP that's stored in a MySQL
I'm trying to get the $url value to display from the MySQL database but
I have been trying to display image from database using php but i am
I am basically trying to retrieve some data from a MySql server, and display
I'm trying to develop web application (php/mysql), sort of blog site where ~10 posts
I'm relatively new to PHP/mySQL and I'm trying to develop a portfolio of my
I am trying to use these if/else if statements to display these php pages.
I am trying to figure out how to display time in PST on my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.