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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:12:20+00:00 2026-05-22T02:12:20+00:00

Lets see if I can explain this. I am displaying a table in PHP

  • 0

Lets see if I can explain this. I am displaying a table in PHP with up/downvote arrows. PHP calls a MySQL query to get the data, then places it in a table with a “while” loop. During this loop, I want to check and see if a user has already upvoted a row, and represent that with a different looking up arrow, etc. This is how I have gone about this so far.

If a user upvotes something, it is stored in a mysql db that looks something like this:

username| upvote| item_id 
Bob     | 1     | 2293
Bob     | 1     | 2295
Sally   | 1     | 2295 

How do I tell php to check if “Bob” has a “1” on item “2293” in the middle of a while loop of a different MySQL array?

echo '<table>';
while ($row = mysqli_fetch_array($data)) {
    echo '<tr>';
//insert php statement checking $row2 to see if Bob has upvoted the data in this row
//so I can place the appropriate arrow here
    echo '</tr></table>';
}
  • 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-22T02:12:21+00:00Added an answer on May 22, 2026 at 2:12 am

    What you need here is probably a MySQL join query. An example could be:

    Your existing SQL:

    SELECT * FROM `items`
    

    We then join all rows from table “upvotes”, but only those rows which the current user has placed:

    The final SQL:

    SELECT `items`.*, COUNT(`upvotes`.`item_id`) AS `upvotes` FROM `items` LEFT JOIN (`upvotes`) ON (`upvotes`.`username` = $currentUserName AND `items`.`id` = `upvotes`.`item_id`) GROUP BY `items`.`id`
    

    Then you should be able to use the same PHP code, but now you can check if “$row[‘upvotes’] > 0”.

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

Sidebar

Related Questions

I screwed up my last post. Lets see if I can get this one
Ok, lets see if I can explain this clearly enough here. My HTML looks
ok, lets see if i can explain this. i have a List<Games> _Games =
Let's see if I can explain myself, I have this models: class BillHeader(models.Model): number
Let's see if I can explain this properly. I am (unfortunately) using Access. I
I will see if I can explain this clearly enough. I have 2 web
Ok, let's see if I can make this make sense. I have a program
Okay, let's see if I can explain what I mean, here's an image to
Who can explain this, please? In my function, I use .remove() to remove one
Let's see if I can explain myself. I use vi-mode in bash, which is

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.