Answer the question
In order to leave comments, you need to log in
How to implement multiple categories for an article?
Good day.
In the database I have a table where posts for the site are stored, which have several categories:
+---+----------+
| id | cat_id |
+---+----------+
| 1 | 1, 5, 11 |
+---+----------+
And the table of the categories themselves:
+---+---------+
| id | name |
+---+--------+
| 1 | cat1 |
+---+--------+
How to do select count() to count how many posts have category 1?
$cat_id = '1';
SELECT count(id) FROM `posts` WHERE cat_id LIKE '%$cat_id%';
Answer the question
In order to leave comments, you need to log in
It will work terribly slowly.
Make a separate table:
+---+----------+
| id | cat_id |
+---+----------+
| 1 | 1 |
+---+----------+
| 1 | 2 |
+---+----------+
| 2 | 3 |
+---+----------+
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question