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.
In PHP, the next step would be to just check whether it evaluates as true or not: