How would I set up a table for topics that a user likes? I have a topics tables and a user table (more actually but simplified for a post on here). There is an ever increasing number of topics as they are user generated, how could I allow users to like pages? Would i put the topic’s id in the user table or the user’s id in the topics table or a create a new likes table? The issue I see is that the number of topics could (potentially) be very large. What could I use to create a system that allows a relationship between a users id and the topics id?
Share
What you could possibly do is a “many to many” table structure
UINT (10) AUTO_INCREMENTUINT (10)(or what ever matches your mainuser_idfield)UINT (10)(or what ever matches your maintopic_idfield)Both
user_idandtopic_idfields would need to be unique together. That means that there can only be once row for a specific like per user. This makes sure (on the database side), that a user will not be allowed to like a topic more than once.Getting a users liked topics would look like this –
Getting the users per like would look like this –
SELECT * FROM user_likes
WHEREtopic_id`=TOPIC_IDAs others have said in their answers and also @trevor in the comments below –