Answer the question
In order to leave comments, you need to log in
How to store subscriptions to tags (categories) and pull them out?
Good afternoon, on the social news site, there is a table of news like
id, title, categories, tags
12, title, ',24,11', ',88,125,'
13, title2, ',34', ',28,154,241,'
I want to add functionality so that the user can subscribe to updates from a specific news category or news tag, at the moment it works like this:
SELECT * FROM `posts` WHERE `tags` LIKE ',1400,' OR `tags` LIKE ',1309,' OR `categories` LIKE ',11,' и т д
Answer the question
In order to leave comments, you need to log in
I can assume that subscriptions are used to display news to which the user has subscribed.
Then you have a table with categories:
id_cat. | name_cat.
1 | example_name_1
2 | example_name_2
...
And the user table as
id_user | name | etc ... | categories
Marked categories by the user can be added to an array, serialized, written as a string.
When a user logs in, get his id and his marked categories
, anserialize the string into an array and you can compose, for example, a query:
SELECT name, your, columns FROM your_table WHERE id IN (1 , 2 ... or supplement the query to select first by tags or t .p.)
In general, this is an option.
Why are you storing user subscriptions in a file cache?
Wouldn't it be better then not to load the server and the database with tables, if the user can only have temporary subscriptions and store them in cookies, for example?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question