我有一个名为product_info包含以下数据的表:
+-------------+------------+----------------+
| title | slug | tags_id |
+-------------+------------+----------------+
| Maserti | /maserati | 10,34,7,110 |
| Ferrari | /ferrari | 10,34,7,107 |
| Rolls Royce | /rollroyce | 6,10,121,64,78 |
| Caterpillar | /cat | 4,8,210,214 |
| Peterbilt | /peterbilt | 8,100,210,214 |
+-------------+------------+----------------+
接下来我有一串php:
$tag = ['id' => 10, 'slug' => 'luxurycars', 'title' => 'LuxuryCars'];
我想搜索我的表,看看我是否有任何带有这个标签的记录。您可以看到标签的 id 存在于tags_id行中。
如您所见,the id of the tag is '10'. 我尝试了很多查询,但结果总是不是我想要的。例如:我想搜索'10'intags_id并且我希望它只匹配,'10'但它匹配10, 107, 110 and 210任何类似或包含10在其中的数字。
我期望的是当我搜索'10'(这是一个名为 LuxuryCars 的标签)时,我想要Maserati, Ferrari and Rolls Royce结果(显然是通过 tags_id 搜索它们在表中)
我不想要Peterbilt and Caterpillar我的结果只是因为他们有一个210与之关联的标签。
请帮忙!谢谢你的时间!