需要:
我需要使用 mysql 选择字段中的提取值。值之间用逗号分隔。
MYSQL 表:
id | city | cusine_type
------------------------------------
1 | Coimbatore | 3 Star Hotel
2 | Coimbatore | 5 Star Hotel, Bakery
3 | Coimbatore | 3 Star Hotel, Ice Cream Store
4 | Coimbatore | Star Hotel, Restaurant
我的 PHP 和 MYSQL 代码
include "db.php";
$city='Coimbatore';
$cus_type='Star Hotel';
$qy=mysqli_query($con, "SELECT * FROM add_res where city='$city' and cusine_type REGEXP CONCAT(',?[$cus_type],?') ");
问题:
上面的代码选择表中的所有行。我只需要第 4 行。
最佳答案
你可以做到
cusine_type LIKE '%$cus_type%'
根据您编辑的问题进行编辑。一个不错的选择是
FIND_IN_SET('$cus_type',cusine_type)
关于php - 如何使用 WHERE 条件从表中的字符串中查找特定值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30588426/