I want to select comma seperated data in query but i have some problems. The page have a categories list and uniq id. And the categories link like this;
<a href="index.php?page=categories&cat=1">Books</a>
I'm catching with $_GET
"cat" id and listing matching users.
My problem when click cat=1, its listing all the user categories have 1 in it. Like id 1 and 11 and 15.
This is the my user table and his selected categories.
| User | Categories |
+----------------+------------+
| Jhon Doe | 1,5,11 |
This is the query;
$catid=$_GET['cat'];
$list=$db->query("
SELECT * FROM users
WHERE categories
LIKE '%$catid%'")->fetchAll(PDO::FETCH_ASSOC);