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 6575849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:26:17+00:00 2026-05-25T15:26:17+00:00

I have voting system on my website, it stores each users vote in table

  • 0

I have voting system on my website, it stores each users vote in table called skmp_voting each record in this database has id, item_id (this is id of article user voted on), and vote_value . vote_value depend’s on what users did, if they voted up value is “1” if they voted down value is “-1”.

I have toparticles.php page where I wan’t to display top articles, so articles that have more up votes. Here is my mysql query to get top articles I have now:

SELECT stories.*, skmp_votes.vote_value FROM stories 
JOIN skmp_votes ON stories.id = skmp_votes.item_id 
ORDER BY skmp_votes.vote_value DESC

It select’s article information from other table called stories and put’s it against vote_value from skmp_votes table.

I’m pretty confident that this isn’t right, as it selects vote_value that is equal to 1 or something, so I need to somehow count all vote_values together and then use mysql query to get top articles.

  • 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-25T15:26:18+00:00Added an answer on May 25, 2026 at 3:26 pm

    It depends on your voting table. As I imagined, it has a row for each vote. In this case, you’ll have to do a sum for the votes wich match an article. i.e.

    SELECT SUM(vote_value) as 'total_votes' FROM skmp_voting WHERE item_id='$article_id';
    

    You use SUM instead of COUNT becouse you want to substract the value from the negative votes.

    EDIT: complementing the answer

    This following Query will get you every article and its total votes, ordered by the total votes (the most voted articles at the top)

    SELECT stories.*, SUM(skmp_votes.vote_value) as 'total_votes' FROM stories 
      JOIN skmp_votes ON stories.id = skmp_votes.item_id 
      ORDER BY skmp_votes.total_votes DESC
    

    To get, say the 5 most voted articles, you just add at the end LIMIT 5

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I have a voting system on my website that stores all votes
I have a model called Vote that gets changed very frequently (people voting on
I have a voting system with two models: Item(id, name) and Vote(id, item_id, user_id).
I've a website with a voting system (like/dislike). The application has been developed by
I have a voting system. When a user clicks Vote button, the vote value
I have a voting system for articles. Articles are stored in 'stories' table and
Which rails voting system plugin or gem that has the following features vote up
Creating a voting system just like stackoverflow. Questions like this have been asking several
I have a project involving a web voting system. The current values and related
This has been driving me nuts for a week now. I have a class

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.