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
I'm trying to display ul>li list using PHP while loop and MYSQL. My database
Quick PHP/MySQL question: I'm trying to display the data from a MySQL database table
i'm trying to learn php/mysql. inserting data into mysql works fine but inserting those
I have a php/mysql poll that I'm trying to modify. It sets a unique
I am trying to learn how to create tags in PHP/MySQL. Does anyone know
I am trying to show Thai Characters in my app PHP / MySQL, data
Im trying to create a iPhone Objective C login page using PHP/MySQL to authenticate.
I am working on a PHP / MySQL stat logging program and am trying
I am trying to teach myself MySQL/PHP from the very beginning. The following code

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.