【发布时间】:2017-02-11 23:26:51
【问题描述】:
假设我有this is the RED color、this is the BLUE color、this is WHATEVER color 的出现,作为它们所属的不同句子的一部分,在表 table 的列 column 的不同单元格中 我的 mySQL 数据库,或者如果这个表在同一行。
----------------------------------------------------------------------------------------
| column |
----------------------------------------------------------------------------------------
| Look, this is the red color which is is not a nice one. |
----------------------------------------------------------------------------------------
| And this is the blue color, I like it more. |
----------------------------------------------------------------------------------------
如何在数据库中搜索this is the % color 以进行精确匹配并将结果放入PHP 数组中,以便我可以完全 输出数组
这是红色
这是蓝色
这是水色
跳过相应句子的所有其他部分?我的意思是我只需要将 这是 CURRENT_WILDCARD_VALUE 颜色 的每一个外观都放入数组中,仅此而已。
到目前为止,我有以下 PHP 代码
global $wpdb;
$query = $wpdb->get_results( "SELECT * FROM table WHERE row LIKE '% this is the % color %'");
print_r($query);
它返回大量额外数据,而我需要它只返回我的搜索词,记住它使用的通配符。
【问题讨论】:
-
您可以使用
like或regexp。是否只允许the和color之间的一系列字母字符?如果是这样,我认为regexp 'this is the [a-zA-Z]+ color会这样做。如果颜色总是大写取出a-z(mysql 正则表达式也可能不区分大小写,所以也许没关系) -
带有标点符号和括号(方和圆)的扩展拉丁字母就足够了,或者您的意思是什么?结果可能很容易成为
this it the LIGHT BLUE color。问题是我也不知道如何创建查询并将结果放入 php 数组中。 -
你目前有什么?解释如何查询和获取有点宽泛..
-
你能用 db 有什么和你想让 PHP 得到什么来更新这个问题吗?
-
这就是查询,你能显示一个实际列的值以及你想从中得到什么吗?