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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:12:14+00:00 2026-06-07T07:12:14+00:00

I have the following tables: users (id,name) items (id,title) users_items (user_id,item_id) users and items

  • 0

I have the following tables:

users (id,name)
items (id,title)
users_items (user_id,item_id)

users and items should be pretty self explanatory. users_items holds whether a user has “favourited” an item. So if user with id 5 has favourited item with id 7, the users_items table will hold the record (5,7) for user_id and item_id respectively.

I want to be able to output all items, but state next to each one, whether the currently logged in user has favourited that item.

Obviously, I could just get all the items and then loop over them and do a separate mysql call to see if any rows are returned from users_items with the relevant user id and lesson id, but is there a nicer way to do this in 1 function. Maybe with some fancy join?

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-06-07T07:12:15+00:00Added an answer on June 7, 2026 at 7:12 am
    SELECT * FROM items LEFT JOIN users_items ON items.id=users_items.item_id AND user_id=1 -- change user_id
    

    In PHP, the next step would be to just check whether it evaluates as true or not:

    if ($row['item_id'])
    {
        // Yes
    }
    else {
        // No
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following tables: users userId|name items itemId|userId|description What I want to achieve:
I have the following tables: users +----------+----------+----------+ | id | name | dob |
I have following two tables 'USERS' and 'GROUPS': USERS -id -name -groupid GROUP -id
I have the following tables: team_members userid teamid users uid name_f name_l friends friend_id
I have the following 3 tables: team_data id team_id team_name team_members userid teamid users
Ok, I have the following Users table: id | name | birthday 1 |
I have the following database design: Employee Table: Username, Name Quiz Table: QuizID, Title,
I have two tables in my database as following: Suggestions Table: ID, Title, Description,
I have three tables to define users: USER: user_id (int), username (varchar) USER_METADATA_FIELD: user_metadata_field_id
I have two tables: users: user_id user_name data: user_id user_data user_time I wan to

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.