php - 比较数据库字段中的字符串

标签 php mysql

你好,我有一个包含列名 id、receiver_id 等的表,现在我想获取记录,其中 sender_id 在用户中是 current_logged,receiver_id 包含 id 中的当前 loggend。

表示receiver_id 包含user_id 的字符串,用 分隔,现在我想检查user_id 是否在receiver_id 中

假设我的 id 是 U112 并且 receiver_id 包含字符串 U112,U123,U157 现在我该如何检查

我尝试了如下但失败了

$selDoc="SELECT * FROM documents WHERE sender_id='U112' OR 'U112' IN (receiver_id) ORDER BY id DESC";

最佳答案

str IN (str2)str == str2 相同。

使用FIND_IN_SET :

FIND_IN_SET('U112', receiver_id)

注意:您可能应该标准化您的模式。这将是一个全表扫描。

关于php - 比较数据库字段中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16167159/

相关文章:

php - 本地点,服务器上的逗号

php - 将月拆分为周并使用 GROUP BY

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

php - 无法在 laravel 3 中捕获 PDOException

返回单个 XML 字符串的 PHP SoapClient() 函数

php - 使用简单的 html dom 获取 url-data 属性

php - Doctrine\DBAL\Schema\SchemaException - 表 'brand_id' 上没有名称为 'clients' 的列

保存对象/Hibernate 时出现 java.lang.NullPointerException

mysql - 为什么sql给出的结果不正确?

mysql - 函数中带有where子句的sql语句