For example, 10 results are displayed from MySQL table products and each product has a like and dislike button. If the user presses like or dislike, the voted table is updated.
Now what i’m having trouble with is: What is the right way of checking if the user has voted or not? What to store If product has been voted with like or dislike?
If there is 300 results, I don’t want to do 300 queries to check in the voted table if the productid and userid is present. What would be the correct way of doing this? I still want to show the results, just not the like or dislike button if the user has voted.
Table A stores products, e.g.
Table B stores user votes, e.g.
Then you can do a simple join query
Then the result set will look like this