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

  • Home
  • SEARCH
  • 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 3348752
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:34:51+00:00 2026-05-18T01:34:51+00:00

I’m making an application that is similar to stackoverflow in that it has ratings

  • 0

I’m making an application that is similar to stackoverflow in that it has ratings for questions and answers and I also have tabs that show comments by oldest, newest and votes. I’m having trouble sorting by votes.

Here is my function:

 /**
     *
     * @param int $threadid
     * @param string $tab
     * @param object $voting referencing Voting.class.php (may not be needed)
     * @return database query/array 
     */
    public function getComments($threadid, $tab = 'oldest', $voting = null) {
        if ($tab == 'oldest') {
            $sql = "SELECT * FROM comments WHERE threadid = :threadid ORDER BY date ASC";
        } else if ($tab == 'newest') {
            $sql = "SELECT * FROM comments WHERE threadid = :threadid ORDER BY date DESC";
        } else if ($tab == 'votes') {
            //i dont know what to do here? read below for more explanation
        } else {
            $sql = "SELECT * FROM comments WHERE threadid = :threadid ORDER BY date ASC";
        }

        $stmt = $this->db->prepare($sql);
        $stmt->bindParam(':threadid', $threadid);
        $stmt->execute();
        $row = $stmt->fetchAll(PDO::FETCH_ASSOC);
        return $row;
    }

Here is my database design:

**comments:** | id | userid | threadid | message | date |

**commentsrating:** | userid | commentid | voteup | votedown |

If ratings are in a separate table from comments is it possible to make a query for $tab == 'votes' that will conform with the rest of the code?

and finally HTML:

<?php //Get comments
if (isset($_GET['tab'])) {
    $getComments = $thread->getComments($threadid, $_GET['tab'], $voting);
} else {
    $getComments = $thread->getComments($threadid);
} ?>

    <?php for ($i = 0; $i < count($getComments); $i++) { ?>
               <p>
    <?php echo $getComments[$i]['message']; ?>
               </p>
               <p>  
                   <span class="bid_votes_count" id="bid_votes_count<?php echo $getComments[$i]['id'] ?>">
    <?php echo $voting->getEffectiveCommentVotes($getComments[$i]['id']) . " votes"; ?>
                   </span>

                   <span class="bid_vote_buttons" id="bid_vote_buttons<?php echo $getComments[$i]['id'] ?>">
                      <a href="javascript:;" class="bid_vote_up" id="<?php echo $getComments[$i]['id'] ?>"></a>
                      <a href="javascript:;" class="bid_vote_down" id="<?php echo $getComments[$i]['id'] ?>"></a>
                  </span>
              </p>
    <?php } ?>

Thanks in advance!
  • 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-18T01:34:52+00:00Added an answer on May 18, 2026 at 1:34 am

    Add rating field to the comments table and maintain it manually or with trigger on commentsrating table.

    Obviously, put there pre-calculated value of the rating and now you are able to have a simple and terrible fast question to perform.

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

Sidebar

Related Questions

No related questions found

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.