WordPress-数据库FIND_IN_SET

时间:2019-02-21 06:33:29

标签: mysql wordpress

我在表的post_content中有数据-wp_posts像这样:

[["ROLL NO.","SID NO","N A M E","M/F"],
["1","1801031101","K. NISHA GOVIND","F"],
["2","1809031101","PATEL RAJ DIRAJ","M"],
["3","1801031901","SHARMA CHARMI J","F"],
["4","1891031101","PATEL HIRAL J","F"],
["5","1801031301","SHAH BRIJESH V","M"],
["6","1801031709","PAREKH HITESH R","M"]]

现在我想比较SID NO并尝试如下操作:

选项1:

$results_match_roll = $wpdb->get_results('SELECT * FROM '.$table_name.' WHERE find_in_set('.$rollNumber.', post_content) '); 

选项2:

$results_match_roll = $wpdb->get_results('SELECT * FROM wp_posts WHERE post_content LIKE '%$rollNumber); 

但是没有运气。请引导我。

1 个答案:

答案 0 :(得分:0)

FIND_IN_SET查找用逗号分隔的值。由于您的SID NO具有",因此您需要进行如下检查。这包括SID NO前后的双引号。

$results_match_roll = $wpdb->get_results("SELECT * FROM $table_name WHERE find_in_set('\"$rollNumber\"', post_content) ");