-3

我有这张桌子

table 'users'

id      name          tag
1       kfir          2,4,7,4
2       avi           1,3,2,5
3       sara          6,8,9,3,5

如何仅显示标记为“5”的用户?

我的代码

$result_total = mysql_query("select * from  users") or die(mysql_error());
$total = mysql_num_rows($result_total);
4

2 回答 2

2

做这个:

$result_total = mysql_query("SELECT * FROM `users` WHERE FIND_IN_SET('5',`tag`)");
$total = mysql_num_rows($result_total);

也尽量不要使用 MySQL 而使用 MySQLi。

于 2013-05-26T10:08:11.023 回答
1

此外,对于非 mysql 特定的解决方案,您可以使用:

select * from users where ','+tag+',' like '%,5,%'
于 2013-05-26T10:33:38.047 回答